2010-07-30 88 views

回答

26

您應該使用UIImageView。它是UIView的子類,你可以用UIImage上的實例設置圖像。

下面是將它添加到另一個UIView的示例。

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

非常感謝你。 – Questions 2010-07-30 02:02:11

2

將圖像添加到項目中例如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

這很簡單,你只分配CGImageRef查看的圖層的內容,例如:

layerView.layer.contents = UIImage(named: "Mario.png")?.cgImage 
相關問題