UIImageView的使用

  UIImageView是继承自UIView 大家都知道

  首相 先来创建它

  第一种创建方式 没参数 直接alloc  init

  UIImageView *imageView1 = [[UIImageView alloc]init];


  第二种 是在创建的时候 就给这个控件一个图片

  UIImageView *imageView1 = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"01"]];

  

  第三种 是在创建的时候 给这个控件两张图片 一种是普通状态下的 一种是高亮状态下的

  UIImageView *imageView1 = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"01"] highlightedImage:[UIImage imageNamed:@"02"]];


     设置普通状态下的图片  若创建的时候已经给这个imageView普通状态的图片了 那么这个图片会覆盖之前的

  imageView1.image = [UIImage imageNamed:@"03"];



    设置高亮状态下的图片 若创建的时候已经给这个imageView高亮状态的图片了 那么这个图片会覆盖之前的

  imageView1.highlightedImage =[UIImage imageNamed:@"04"];

 

    让imageView变成高亮状态 默认是普通状态

  imageView1.highlighted = YES;


     设置imageView是否可以和用户交互 默认是不可以的

  我们通常在添加手势的时候 会把这个打开

  imageView1.userInteractionEnabled = YES;


   

     默认是空的 如果被设定了颜色 ,这个颜色就会被应用于和这个imageView任何相关的模块

  这个属性 是对view的一个染色 看官方文档 说的

   UIImageRenderingModeAutomatic,           

   UIImageRenderingModeAlwaysOriginal,

   UIImageRenderingModeAlwaysTemplate,

  只有这样创建的时候 tintColor才能显示出效果来 而且必须是UIImageRenderingModeAlwaysTemplate平铺状态下才能显示出来

  其他两种状态都显示不出来,而且是平铺状态的时候,若不指定颜色,默认是蓝色的

  imageView1.image = [[UIImage imageNamed:@"03"] imageWithRenderingMode:UIImageRenderingModeAutomatic];

  对这个属性理解的比较浅   求大神指导

     imageView1.tintColor = [UIColor redColor];


    普通状态下的动画数组  

  NSArray *normalArray = [NSArray arrayWithObjects:

                       [UIImage imageNamed:@"loading_00000"],

                       [UIImage imageNamed:@"loading_00001"],

                       [UIImage imageNamed:@"loading_00002"],

                       [UIImage imageNamed:@"loading_00003"],

                       [UIImage imageNamed:@"loading_00004"],

                       [UIImage imageNamed:@"loading_00005"],

                       [UIImage imageNamed:@"loading_00006"],

                       [UIImage imageNamed:@"loading_00007"],

                       [UIImage imageNamed:@"loading_00008"],

                       [UIImage imageNamed:@"loading_00009"],

                       [UIImage imageNamed:@"loading_00010"],

                       [UIImage imageNamed:@"loading_00011"],

                       [UIImage imageNamed:@"loading_00012"],

                       [UIImage imageNamed:@"loading_00013"],

                       nil];

       设置在普通状态下 动画的数组

      imageView1.animationImages = normalArray;


       高亮下的动画数组

   NSArray *highArray = [NSArray arrayWithObjects:

                          [UIImage imageNamed:@"loading_00013"],

                          [UIImage imageNamed:@"loading_00012"],

                          [UIImage imageNamed:@"loading_00011"],

                          [UIImage imageNamed:@"loading_00010"],

                          [UIImage imageNamed:@"loading_00009"],

                          [UIImage imageNamed:@"loading_00008"],

                          [UIImage imageNamed:@"loading_00007"],

                          [UIImage imageNamed:@"loading_00006"],

                          [UIImage imageNamed:@"loading_00005"],

                          [UIImage imageNamed:@"loading_00004"],

                          [UIImage imageNamed:@"loading_00003"],

                          [UIImage imageNamed:@"loading_00002"],

                          [UIImage imageNamed:@"loading_00001"],

                          [UIImage imageNamed:@"loading_00000"],

                          nil];

       设置在高亮状态下的动画的数组

   imageView1.highlightedAnimationImages = highArray;


     设置动画的时间 是按秒算的

  默认的时间是每秒三十张图片 也就是假如你有10张图片 那么默认的时间是10/30

  imageView1.animationDuration = 2;

    

    

     设置动画重复的次数 默认是无限次的 0就是无限次 默认count =

     imageView1.animationRepeatCount = 2;

 

     最后把这个imageView添加上去

  _imageView1 = imageView1;

  imageView1.frame = CGRectMake(80, 200, 200, 200*400/640);

  [self.view addSubview:imageView1];



-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{  

     这个方法 返回一个bool 来判断当前imageView是否在执行动画

  if ([_imageView1 isAnimating]) {

    imageView停止动画

    [_imageView1 stopAnimating];

  }else{

    开始动画 从数组的第一张图片开始

    [_imageView1 startAnimating];

  }

}






  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值