10.UIImageView

UIImageView

初始化

    //初始化
    UIImageView *imageView = [[UIImageView alloc ] init];

    //方法一:
    //加载图片方法一
    UIImage *image = [UIImage imageNamed: @"图片名"];
    imageView.image = image;

    //加载图片方法二
    NSString *path = [[NSBundle mainBundle] pathForResource:@"命名" ofType:@"格式"];
    UIImage *image = [UIImage imageWithContentsOfFile: path];

图片显示效果

    //设置边框为圆角和大小
    imageView.layer.masksToBounds = YES;
    imageView.layer.cornerRadius = 10;

    //设置边框颜色和大小
    imageView.layer.borderColor = [UIColor orangeColor].CGColor;
    imageView.layer.borderWidth = 2;

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

    // 将图片尺寸调整为与内容图片相同
    [imageView sizeToFit];

    //缩放图片的高度和宽度的倍数
    imageView.transform = CGAffineTransformMakeScale(CGFloat scale_w, CGFloat scale_h);

图片显示设置

    //UIViewContentModeRedraw          重绘   
    //UIViewContentModeCenter          中心
    //UIViewContentModeTop             中上
    //UIViewContentModeBottom          中下
    //UIViewContentModeLeft            中左
    //UIViewContentModeRight           中右
    //UIViewContentModeTopLeft         左上
    //UIViewContentModeTopRight        右上
    //UIViewContentModeBottomLeft      左下
    //UIViewContentModeBottomRight     右下
    //UIViewContentModeScaleToFill     填充整个View
    //UIViewContentModeScaleAspectFit  不超出view高/宽度,伸缩至最大尺寸(不改变图片比例)
    //UIViewContentModeScaleAspectFill 超出view高/宽度,伸缩至最大尺寸(不改变图片比例)
    imageView.contentMode = UIViewContentModeScaleAspectFit;

    //以图片为中心点设置x和y
    imageView.center = CGPointMake(x , y);

添加响应事件

    //开启使用交互接口
    imageView.userInteractionEnabled = YES;

    //添加响应条件
    UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapImageView)];

    [imageView addGestureRecognizer:singleTap];

幻灯片效果

    UIImage *tmp1 = [UIImage imageNamed:@"1.jpg"];
    UIImage *tmp2 = [UIImage imageNamed:@"2.jpg"];
    UIImage *tmp3 = [UIImage imageNamed:@"3.jpg"];
    UIImage *tmp4 = [UIImage imageNamed:@"4.png"];
    NSArray *imageArr = @[tmp1, tmp2, tmp3, tmp4];

    //添加图片册
    iView.animationImages = imageArr;

    //播放次数,0为无数次播放
    iView.animationRepeatCount = 0;

    //播放x秒播放完图片册
    iView.animationDuration = 4;

    //停止播放
    //[iView stopAnimating];

    //开始播放
    [iView startAnimating];

这里写图片描述
源码:https://yunpan.cn/cSdVKavV8RqFT (提取码:1e6f)

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值