您的位置:首页 > 产品设计 > UI/UE

10.UIImageView

2016-05-18 16:33 423 查看
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)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: