2010-07-30 47 views

Trả lời

26

Bạn nên sử dụng UIImageView. Nó là một phân lớp của UIView và bạn có thể thiết lập hình ảnh với một thể hiện trên UIImage.

Dưới đây là ví dụ để thêm nó vào một UIView khác.

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

thank you very much. – Questions

2

Thêm hình ảnh vào dự án của bạn, ví dụ: Spinner.png

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

Nó rất dễ dàng chỉ cần gán CGImageRef để xem nội dung của layer của, ví dụ:

layerView.layer.contents = UIImage(named: "Mario.png")?.cgImage 
Các vấn đề liên quan