Uso de la vista de imagen
Las vistas de imagen se utilizan para mostrar una sola imagen o imágenes en una secuencia animada.
Propiedades importantes
- image
- highlightedImage
- userInteractionEnabled
- animationImages
- animationRepeatCount
Métodos importantes
- (id)initWithImage:(UIImage *)image
- (id)initWithImage:(UIImage *)image highlightedImage: (UIImage *)highlightedImage
- (void)startAnimating
- (void)stopAnimating
Agregar método personalizado addImageView
-(void)addImageView{
UIImageView *imgview = [[UIImageView alloc]
initWithFrame:CGRectMake(10, 10, 300, 400)];
[imgview setImage:[UIImage imageNamed:@"AppleUSA1.jpg"]];
[imgview setContentMode:UIViewContentModeScaleAspectFit];
[self.view addSubview:imgview];
}
Agregar otro método personalizado addImageViewWithAnimation
Este método explica cómo animar las imágenes en imageView.
-(void)addImageViewWithAnimation{
UIImageView *imgview = [[UIImageView alloc]
initWithFrame:CGRectMake(10, 10, 300, 400)];
// set an animation
imgview.animationImages = [NSArray arrayWithObjects:
[UIImage imageNamed:@"AppleUSA1.jpg"],
[UIImage imageNamed:@"AppleUSA2.jpg"], nil];
imgview.animationDuration = 4.0;
imgview.contentMode = UIViewContentModeCenter;
[imgview startAnimating];
[self.view addSubview:imgview];
}
Nota:Debemos agregar imágenes llamadas "AppleUSA1.jpg" y "AppleUSA2.jpg" a nuestro proyecto. Esto se puede hacer arrastrando las imágenes al área de navegación, donde se enumeran los archivos del proyecto.
Actualice viewDidLoad en ViewController.m como se muestra a continuación
(void)viewDidLoad
{
[super viewDidLoad];
[self addImageView];
}
Otras extensiones