Image View用于显示单个图像或动画序列。
Image View - 重要属性
- image
- HighlightingImage
- userInteractionEnabled
- animationImages
- animationRepeatCount
Image View - 重要方法
- (id)initWithImage:(UIImage *)image - (id)initWithImage:(UIImage *)image highlightedImage: (UIImage *)highlightedImage - (void)startAnimating - (void)stopAnimating
Image View - 自定义方法1
-(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]; }
Image View - 自定义方法2
此方法说明了如何在imageView中对图像进行动画处理。
-(void)addImageViewWithAnimation { UIImageView *imgview = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, 300, 400)]; //设置动画 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]; }
无涯教程必须将名为" AppleUSA1.jpg"和" AppleUSA2.jpg"的图像添加到无涯教程的项目中,这可以通过将图像拖到列出项目文件的导航器区域中来完成。
更新ViewController.m中的viewDidLoad,如下所示:
(void)viewDidLoad { [super viewDidLoad]; [self addImageView]; }
运行应用程序时,将获得以下输出-
您可以尝试调用addImageViewWithAnimation而不是addImageView方法来查看图像视图的动画效果。