ios UIImageView简单使用

UIImageView简单使用方法:

 

//初始化
UIImageView *imageView = [ [UIImageView alloc] initWithFrame:CGRectMake(20, 20, 200, 200) ];       
UIImageView *imageView = [ [UIImageView alloc] initWithImage: (image) ];
UIImageView *imageView = [ [UIImageView alloc] initWithImage: (image) highlightedImage:(image2) ];

//设置中间点位置
imageView.center = CGPointMake(CGPoint x, CGPoint y);

//是否隐藏
imageView.hidden = YES;

//设置透明度
imageView.alpha = 0.5;

//添加图片
imageView.image = image;

//高亮时图片
imageView.highlightedImage = image;

//视图的图层上的子图层,如果超出父图层的部分就截取掉 
imageView.layer.masksToBounds = YES;

//设置圆角
imageView.layer.cornerRadius = 10;     //如果变成园,则为半径

//设置边框大小
imageView.layer.borderWidth = 1;

//设置边框颜色
imageView.layer.borderColor = [UIColor redColor];

//设置图片的显示方式 居中,缩放等等
imageView.contentMode = UIViewContentModeScaleAspectFill;
typedef enum {
      UIViewContentModeScaleToFill;
      UIViewContentModeScaleAspectFit;
      UIViewContentModeScaleAspectFill;
      UIViewContentModeRedraw
      UIViewContentModeCenter
      UIViewContentModeTop
      UIViewContentModeBottom
      UIViewContentModeLeft
      UIViewContentModeRight
      UIViewContentModeTopLeft
      UIViewContentModeTopRight
      UIViewContentModeBottomLeft
      UIViewContentModeBottomRight
} UIViewContentModeType;

//添加事件
imageView.userInteractionEnabled = YES;
UITapGestureRecognizer *singleTap = [ [UITapGestureRecognizer alloc] initWithTarget: self action: @selector(tapImageView:) ];
[ imageView addGestureRecognizer: singleTap];

//图片播放
UIImage *image1 = [UIImage imageNamed:@"image1.png"];
UIImage *image2 = [UIImage imageNamed:@"image2.png"];
UIImage *image3 = [UIImage imageNamed:@"image3.png"];
NSArray *imageArr  = @[image1, image2, image3];
imageView.animationImages = imageArr;
imageView.animationDuration = [imageArr count];   //播放图片持续时间
imageView.animationRepeatCount = 0;   //播放多少遍,0表示无数遍
[imageView startAnimating];  //开始播放
[imageView stopAnimating];  //停止播放

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值