2010-07-30 11 views

Respuesta

26

Debe usar UIImageView. Es una subclase de UIView y puedes establecer la imagen con una instancia en UIImage.

Aquí hay un ejemplo para agregarlo a otra UIView.

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

muchas gracias. – Questions

2

Agregue una imagen a su proyecto p. 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

Es muy fácil sólo asignar CGImageRef para ver el contenido de la capa, por ejemplo:

layerView.layer.contents = UIImage(named: "Mario.png")?.cgImage 
Cuestiones relacionadas