iOS开发-UIImageView的contentMode属性
2015-08-20 14:32
531 查看
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.显示正常的图片
2.
3.
ref http://blog.csdn.net/sqc3375177/article/details/17415635
UIViewContentModeScaleToFill
UIViewContentModeScaleAspectFit
UIViewContentModeScaleAspectFill
UIViewContentModeRedraw
UIViewContentModeCenter
UIViewContentModeTop
UIViewContentModeBottom
UIViewContentModeLeft
UIViewContentModeRight
UIViewContentModeTopLeft
UIViewContentModeTopRight
UIViewContentModeBottomLeft
UIViewContentModeBottomRight
注意以上几个常量,凡是没有带Scale的,当图片尺寸超过 ImageView尺寸时,只有部分显示在ImageView中。UIViewContentModeScaleToFill属性会导致图片变形。UIViewContentModeScaleAspectFit会保证图片比例不变,而且全部显示在ImageView中,这意味着ImageView会有部分空白。UIViewContentModeScaleAspectFill也会证图片比例不变,但是是填充整个ImageView的,可能只有部分图片显示出来。
例如:
1.显示正常的图片
_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.
_image.contentMode = UIViewContentModeScaleAspectFill;
3.
_image.contentMode = UIViewContentModeScaleAspectFit;
ref http://blog.csdn.net/sqc3375177/article/details/17415635
相关文章推荐
- UIView的使用setNeedsDisplay
- LeetCode96_Unique Binary Search Trees(求1到n这些节点可以组成多少种不同的二叉查找树) Java题解
- UISegmentControl的属性和方法
- UITableView滑动删除学习笔记
- UI架构设计的演化
- iOS多线程——NSOperation & NSOperationQueue
- List<NameValuePair> params = new ArrayList<NameValuePair>();
- php:$_REQUEST、$_POST、$_GET的区别和联系
- ios uitableview header不随着滚动
- The Unique MST
- requireJS简单的学习门户网站
- 开源作品-PHP写的在线文件管理工具(单文件绿色版)-SuExplorer_PHP_2_0
- QSqlQueryModel读取数据库,提示 database locked
- 搞定百度编辑器UEditor
- 在UINavigation上添加UISearchBar
- 虚拟化--004 your account is no authorized to perform the requested action
- UITableViewCell的重用问题
- IOS开发 - UIApplication的常见使用
- UE4 GPU Profiling
- UE4 CPU Profiling