2010-07-30 90 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 
相关问题