UIImageView 的contentMode属性应用
2016-05-03 22:55
399 查看
UIImageView 的contentMode这个属性是用来设置图片的显示方式,如居中、居右,是否缩放等,有以下几个常量可供设定:
UIViewContentModeScaleToFill
UIViewContentModeScaleAspectFit
UIViewContentModeScaleAspectFill
UIViewContentModeRedraw
UIViewContentModeCenter
UIViewContentModeTop
UIViewContentModeBottom
UIViewContentModeLeft
UIViewContentModeRight
UIViewContentModeTopLeft
UIViewContentModeTopRight
UIViewContentModeBottomLeft
UIViewContentModeBottomRight
注意以上几个常量,凡是没有带Scale的,当图片尺寸超过 ImageView尺寸时,只有部分显示在ImageView中。UIViewContentModeScaleToFill属性会导致图片变形。UIViewContentModeScaleAspectFit会保证图片比例不变,而且全部显示在ImageView中,这意味着ImageView会有部分空白。UIViewContentModeScaleAspectFill也会证图片比例不变,但是是填充整个ImageView的,可能只有部分图片显示出来。
例如:
1。显示正常的图片
[cpp] view
plaincopy
_image = [[UIImageView alloc] init];
image = [UIImage imageNamed:@"12.jpeg"];
_image.backgroundColor = [UIColor brownColor];
_image.clipsToBounds = YES;
_image.frame = CGRectMake(100, 130, 100, 100);
_image.contentMode = UIViewContentModeScaleToFill;
[self.view addSubview:_image];
2。
[cpp] view
plaincopy
_image.contentMode = UIViewContentModeScaleAspectFill;
3。
[cpp] view
plaincopy
_image.contentMode = UIViewContentModeScaleAspectFit;
UIViewContentModeScaleToFill
UIViewContentModeScaleAspectFit
UIViewContentModeScaleAspectFill
UIViewContentModeRedraw
UIViewContentModeCenter
UIViewContentModeTop
UIViewContentModeBottom
UIViewContentModeLeft
UIViewContentModeRight
UIViewContentModeTopLeft
UIViewContentModeTopRight
UIViewContentModeBottomLeft
UIViewContentModeBottomRight
注意以上几个常量,凡是没有带Scale的,当图片尺寸超过 ImageView尺寸时,只有部分显示在ImageView中。UIViewContentModeScaleToFill属性会导致图片变形。UIViewContentModeScaleAspectFit会保证图片比例不变,而且全部显示在ImageView中,这意味着ImageView会有部分空白。UIViewContentModeScaleAspectFill也会证图片比例不变,但是是填充整个ImageView的,可能只有部分图片显示出来。
例如:
1。显示正常的图片
[cpp] view
plaincopy
_image = [[UIImageView alloc] init];
image = [UIImage imageNamed:@"12.jpeg"];
_image.backgroundColor = [UIColor brownColor];
_image.clipsToBounds = YES;
_image.frame = CGRectMake(100, 130, 100, 100);
_image.contentMode = UIViewContentModeScaleToFill;
[self.view addSubview:_image];
2。
[cpp] view
plaincopy
_image.contentMode = UIViewContentModeScaleAspectFill;
3。
[cpp] view
plaincopy
_image.contentMode = UIViewContentModeScaleAspectFit;
相关文章推荐
- 83_自定义FastJsonRequest
- android 用户登陆注册UI设计之 edittext (就是输入用户名和密码的文本框)
- 知识梳理:Android子线程中更新UI的3种方法
- POJ 3498 —— March of the Penguins (枚举+最大流)
- poj 1458 Common Subsequence -- 最长公共子序列
- Xcode Build Search Paths设置
- UIImage两种初始化的区别
- UE4:文件读写
- UITableView进阶,cell刷新,界面返回 保持所选cell
- LeetCode|Top K Frequent Elements
- js闭包个人理解--to be continued
- 将属性文件以key-value值形式输出的工具类
- StringBuilder 和StringBuffer 的区别
- 提取classes中properties的value(JAVA)
- UVA 11404 Palindromic Subsequence LCS
- 类型化和泛型化的 Table View Controller
- HashTable 和 HashMap的区别 StringBuffer 和Builder的区别
- fetchxml分页和QueryExpression分页
- 山东省第四届ACM省赛 A SDUT 2603 Rescue The Princess(简单数学题)
- java StringBuilder类的常用方法