一、UIImageView介绍
一个UIImageView提供基于view的容器,用来显示单个图片或者可以用来展示一系列图片的动画。对于动画图片,UIImageView类提供动画周期和动画频率的控制方法。你可以自由的开始和停止动画。
二、相关方法
1、初始化对象
- (instancetype nonnull)initWithImage:(UIImage * nullable)image
- (instancetype nonnull)initWithImage:(UIImage * nullable)image highlightedImage:(UIImage * nullable)highlightedImage
2、image data
@property(nonatomic, strong) UIImage *image
@property(nonatomic, strong) UIImage *highlightedImage
@property(nonatomic, copy) NSArray <UIImage *> *animationImages
@property(nonatomic, copy) NSArray <UIImage *> *highlightedAnimationImages
@property(nonatomic) NSTimeInterval animationDuration
@property(nonatomic) NSInteger animationRepeatCount
- (void)startAnimating
- (void)stopAnimating
- (BOOL)isAnimating
@property(nonatomic, getter=isUserInteractionEnabled) BOOL userInteractionEnabled
@property(nonatomic, getter=isHighlighted) BOOL highlighted
@property(nonatomic, strong) UIColor * __null_unspecified tintColor
三相关列子
1、创建一个显示单个图片的UIInageView。
UIImageView *imageView
= [[UIImageView alloc] initWithFrame:CGRectMake(10,20,self.view.frame.size.width - 20, 100)];
imageView.image = [UIImage imageNamed:@"bgnormol.png"];
imageView.backgroundColor = [UIColor whiteColor];//<span style="font-family: Arial, Helvetica, sans-serif;">UIImageView 背景颜色
</span> imageView.highlightedImage = [UIImage imageNamed:@"bghighlighted.png"];//高亮下的图片
imageView.highlighted = YES;// 设置高亮显示
imageView.contentMode = UIViewContentModeScaleAspectFit;//设置分辨率匹配
[self.view addSubview:imageView];
2、创建显示一系列动画的UIImageView
UIImageView *myImage = [[UIImageView alloc]initWithFrame:CGRectMake(10, 280, self.view.bounds.size.width-20, 100)]; //新建一个UIImageView myImage.backgroundColor = [UIColor whiteColor];//背景颜色
UIImage *ig1= [UIImage imageNamed:@"bg1"];
UIImage *ig2= [UIImage imageNamed:@"bg2"];
UIImage *ig3= [UIImage imageNamed:@"bg3"];
UIImage *ig4= [UIImage imageNamed:@"bg4"];
myImage.animationImages = @[ig1,ig2,ig3,ig4];//设置其动画图片
myImage.animationDuration = 3;//动画事件
myImage.contentMode =UIViewContentModeScaleAspectFit;//设置内容模式,伸缩之类的操作
[myImage startAnimating];//设置开始动画
[self.view addSubview:myImage];