UI---UIImageView

UIImageView是iOS中⽤用于显⽰示图⽚片的类,iOS中⼏几乎所有看到的图⽚片,都是由这个类来显⽰示的.

NS_CLASS_AVAILABLE_IOS(2_0) @interface UIImageView : UIView {
  @private
    id _storage;
}

上代码

 UIImageView *imv = [[UIImageView alloc] initWithFrame:[UIScreen mainScreen].bounds];
    imv.backgroundColor = [UIColor cyanColor];
    //第一种获取图片方式
//    imv.image = [UIImage imageNamed:@"1.jpg"];//如果是pnj格式的图片则可以省略格式名
    //获取bundle里面图片的第二种形式
    NSString *path = [[NSBundle mainBundle]pathForResource:@"1" ofType:@"jpg"];//@"1.jpg"  nil
    //也可以写成
    NSString *path = [[NSBundle mainBundle]pathForResource:@"1.jpg" ofType:nil];
    /*
    但不可以写成
    NSString *path = [[NSBundle mainBundle]pathForResource:nil ofType:@"1.jpg"];
*/
    imv.image = [UIImage imageWithContentsOfFile:path];

[NSBundle mainBundle]是指这里

添加动态图的方式

    UIImage *img1 = [UIImage imageNamed:@"1.tiff"];
    UIImage *img2 = [UIImage imageNamed:@"2.tiff"];
    UIImage *img3 = [UIImage imageNamed:@"3.tiff"];
    UIImage *img4 = [UIImage imageNamed:@"4.tiff"];
    UIImage *img5 = [UIImage imageNamed:@"5.tiff"];
    UIImage *img6 = [UIImage imageNamed:@"6.tiff"];
    imv.animationImages = @[img1,img2,img3,img4,img5,img6];

    //动画循环的次数
     imv.animationRepeatCount = 10;

    //动画每次的时间
    imv.animationDuration = 1;

    //让动画开始的方法
    [imv startAnimating];
    //让动画停止
    [imv stopAnimating];
#####
//imageView默认的userInteractionEnabled是NO,会阻断响应链
    //意思是如果在图片上面加了例如button这样需要相应的东西,就一定要把imageView的userInteractionEnabled设置为YES;
    imv.userInteractionEnabled = YES;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值