UIImageView是加载图片的控件,顾名思义,就是来放置图片。
- 创建一个UIImageView
//方法一
UIImageView*iv=[[UIImageView alloc]init];
//方法二
UIImageView *iv=[[UIImageView alloc]initWithFrame:CGRectMake(CGFloat x, CGFloat y, CGFloat w
idth, CGFloat height)];
//添加到View上
[self.view addSubview:iv];
2. 添加图片
UIImage *image=[UIImage imageNamed:@"图片名"];
//UIImageView是承载UIImage的类
[iv addSubview:image];
3. 播放一系列图片
UIImage *image1=[UIImage imageNamed:@"1"];
UIImage *image2=[UIImage imageNamed:@"2"];
UIImage *image3=[UIImage imageNamed:@"3"];
//将图片放到数组
NSMutableArray *arr=@[image1,image2,image3];
iv.animationImages=arr;
//播放时间
iv.animationDuration=1;
//播放次数-默认无限循环
iv.animationRepeatCount=1;
//开始动画
[iv startAnimating];
4. 设置点击事件
//一定要先将userInteractionEnabled设置为YES
iv.userInteractionEnabled=YES;
UITapGestureRecognizer*Tap=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(<#selector#>)];
[iv addGestureRecognizer:Tap];