UIImageView的介绍和方法

UIImageView使用教程
本文详细介绍了如何使用UIImageView控件加载和播放图片,包括创建UIImageView、添加图片、播放一系列图片及设置点击事件等步骤。

UIImageView是加载图片的控件,顾名思义,就是来放置图片。 

  1. 创建一个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];

 

 

 

转载于:https://my.oschina.net/sgcllr/blog/748973

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值