10.UIImageView
2016-05-18 16:33
423 查看
UIImageView
初始化
图片显示效果
图片显示设置
添加响应事件
幻灯片效果
![](http://img.blog.csdn.net/20160518163229665)
源码:https://yunpan.cn/cSdVKavV8RqFT (提取码:1e6f)
初始化
图片显示效果
图片显示设置
添加响应事件
幻灯片效果
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)
相关文章推荐
- IOS开发 REST请求 ASIHTTPRequest用法
- iOS UITextFiled 后边的小叉号或是一次性删除输入的文字
- AndroidStudio导入新项目一直卡在Building gradle project info的解决解决方案
- PHP_SELF、 SCRIPT_NAME、 REQUEST_URI区别
- 一图了解View的生命周期,自定义view,invalidate()和requestLayout()调用
- Vue.js-----轻量高效的MVVM框架(二、Vue.js的简单入门)
- UEFI 安装win10 ubuntu双系统
- MultipartEntityBuilder.addTextBody 中文乱码
- ios学习--UIColor的你想知道的所有
- UIResponder
- UIControl
- 模拟Quintus引擎框架编码
- break continue 区别 以及实例
- 异步加载的requirejs,你值得拥有
- UITableView 调整分割线长度 等不常用属性总结
- jmeter 非GUI模式下测试报错An error occurred: Unknown arg:
- 非 GUI 模式运行 JMeter 压力测试
- RMQ (Range Minimum/Maximum Query)算法
- 浅析C#中StringBuilder类的高效及与String的对比
- UiAutomator——点击难以识别的控件技巧