2010-07-30 6 views

답변

26

UIImageView를 사용해야합니다. UIView의 하위 클래스이며 UIImage의 인스턴스로 이미지를 설정할 수 있습니다.

다음은 다른 UIView에 추가하는 예입니다.

UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"nameofimage.png"]]; 
[myUIView addSubview:imageView]; 
+0

대단히 감사합니다. – Questions

2

예를 들어 이미지를 프로젝트에 추가하십시오.

NSString *path = [[NSBundle mainBundle] pathForResource: @"Spinner" ofType: @"png"]; 
NSLog(@"path: %@", path); 
UIImage* image = [[UIImage alloc] initWithContentsOfFile: path]; 
UIImageView *imageView = [[UIImageView alloc] initWithImage: image]; 
[self.view addSubview: imageView]; 
0

을 Spinner.png 그것은 예를 들면, 단지의 레이어의 내용을 볼 수 CGImageRef를 할당 매우 쉽습니다 :

layerView.layer.contents = UIImage(named: "Mario.png")?.cgImage 
관련 문제