UIViewContentMode 都有哪些值:

typedef NS_ENUM(NSInteger, UIViewContentMode) {
UIViewContentModeScaleToFill,
UIViewContentModeScaleAspectFit, // contents scaled to fit with fixed aspect. remainder is transparent
UIViewContentModeScaleAspectFill, // contents scaled to fill with fixed aspect. some portion of content may be clipped.
UIViewContentModeRedraw, // redraw on bounds change (calls -setNeedsDisplay)
UIViewContentModeCenter, // contents remain same size. positioned adjusted.
UIViewContentModeTop,
UIViewContentModeBottom,
UIViewContentModeLeft,
UIViewContentModeRight,
UIViewContentModeTopLeft,
UIViewContentModeTopRight,
UIViewContentModeBottomLeft,
UIViewContentModeBottomRight,
};

默认值是 0,也就是:

UIViewContentModeScaleToFill

一个个来理解下吧:

  • UIViewContentModeScaleToFill:表示完全填充在 frame 里 不按比例来。
  • UIViewContentModeScaleAspectFit:保持比例,都在 frame 内。
  • UIViewContentModeScaleAspectFill:保持比例,填满但 frame 外也有。
  • UIViewContentModeRedraw:每次设置或更改frame的时候自动调用drawRect.

其他的是相似的,好理解:

  • UIViewContentModeCenter:这个 image 的中心与 frame 的中心重合。
  • UIViewContentModeTop:这个 image 的上边缘与 frame 的上边缘重合。
  • UIViewContentModeBottom:这个 image 的下边缘与 frame 的下边缘重合。
  • UIViewContentModeLeft:这个 image 的左边缘与 frame 的左边缘重合。
  • UIViewContentModeRight:这个 image 的右边缘与 frame 的右边缘重合。
  • UIViewContentModeTopLeft:类似。
  • UIViewContentModeTopRight:类似。
  • UIViewContentModeBottomLeft:类似。
  • UIViewContentModeBottomRight:类似。

经常用到的:1.比如长图的显示 按一定的比例只显示中间的一部分 其他的裁剪掉

   self.imageView.contentMode = UIViewContentModeScaleAspectFill;
self.imageView.clipsToBounds = YES;

UIImageView的contentMode属性的更多相关文章

  1. [BS-24] UIImageView的contentMode属性

    UIImageView的contentMode属性   所有的UIView都有个contentMode属性,UIImageView继承自UIView,我们在使用UIImageView时,经常要考虑这些 ...

  2. UIImageView 的contentMode属性应用

    UIImageView 的contentMode这个属性是用来设置图片的显示方式,如居中.居右,是否缩放等,有以下几个常量可供设定:UIViewContentModeScaleToFillUIView ...

  3. UIImageView 的contentMode属性 浅析

    UIImageView 的contentMode这个属性是用来设置图片的显示方式,如居中.居右,是否缩放等,有以下几个常量可供设定:UIViewContentModeScaleToFillUIView ...

  4. iOS开发-UIImageView的contentMode属性

    UIImageView 的contentMode这个属性是用来设置图片的显示方式,如居中.居右,是否缩放等,有以下几个常量可供设定:UIViewContentModeScaleToFillUIView ...

  5. UIImageView 的contentMode属性

    UIViewContentModeScaleToFill UIViewContentModeScaleAspectFit UIViewContentModeScaleAspectFill UIView ...

  6. IOS UIImageView的contentMode属性

    红框表示imageView的frame,下面的图片是原图大小UIViewContentModeScaleToFill,       默认,对图片进行拉伸处理(不是按比例),是充满bouns UIVie ...

  7. 重写UIImageView的image属性

    重写UIImageView的image属性 效果: 当你重写了UIImageView的image属性后你就会对UIImageView怎么显示图片了如指掌了:) 源码: UIImageView.h  + ...

  8. 通过 CALayer 修改 UIImageView 的界面属性

    界面属性的修改是每一个开发者必须知道的,为什么我就记不住呢, shit, 又耽误了时间,为了防止再找不到,特把一些常用的 CALayer属性记在这里,顺便分享 1.设置阴影 1 imageView.l ...

  9. 0119——UIImageView的一些属性 和 简单动画实现

    1.contentMode view.contentMode = UIViewContentModeScaleAspectFill; 2.是否实现触摸 3.简单实现动画 图片的名字为campFire0 ...

随机推荐

  1. if 结构和三目运算和switch语句

    if语句需要注意的地方: if判断只能接一个语句,存在多个语句时,用块语句表示{},若在if判断后 直接加“:”相当于if判断后加一个空语句,即使条件成立什么也不会干! 1. if的第一种形态(真假) ...

  2. c 变量的存储类型auto等(基础知识)和c函数变量

    总结 1).在c语言中每一个变量和函数有两个属性:数据类型和数据的存储类别. 2). 对数据型(如整型.字符型等).存储类别指的是数据在内存中存储的方式. 存储方式分为两大类: 静态存储类和动态存储类 ...

  3. VUE系列三:实现跨域请求(fetch/axios/proxytable)

    1. 在 config/index.js 配置文件中配置proxyTable 'use strict' // Template version: 1.3.1 // see http://vuejs-t ...

  4. AWT和Swing之间的基本区别

    AWT和Swing之间的基本区别:AWT 是基于本地方法的C/C++程序,其运行速度比较快:Swing是基于AWT 的Java程序,其运行速度比较慢. 对于一个嵌入式应用来说,目标平台的硬件资源往往非 ...

  5. C#提高------------------------Attribute自定制概念

    C#基础知识梳理系列八:定制特性Attribute   摘 要 设计类型的时候可以使用各种成员来描述该类型的信息,但有时候我们可能不太愿意将一些附加信息放到类的内部,因为这样,可能会给类型本身的信息描 ...

  6. 导入Maven项目后,Eclipse提示“Missing artifact ”类的错误

    导入Maven项目后,Eclipse提示“Missing artifact ”类的错误 标签: Maven Missing art 2016-08-15 16:05 679人阅读 评论(0) 收藏 举 ...

  7. python调用ansible接口API执行命令

    python版本:Python 2.6.6 ansible版本:ansible 2.3.1.0      下载地址:https://releases.ansible.com/ansible/ 调用脚本 ...

  8. vegan 包进行Adonis 分析

    Adonis 分析 是基于距离矩阵的多变量方差置换分析, 代码示例: 默认使用bray 距离来计算样本间的距离矩阵 参考资料: https://www.rdocumentation.org/packa ...

  9. hibernate.cfg配置mysql方言

    hibernate自动建表,mysql高版本不支持 type=InnoDB 中的type关键字. 应该使用engine关键字 而非type 所以需要在hibernate.cfg.xml中配置方言.否则 ...

  10. ubuntu 12.04和Windows 7双系统的安装方法

    ubuntu是一个操作系统,和安卓一样同是linux内核下的子民,所以来这贡献一下,也求JW放出安卓4.0原生正式版,我只想要这个. 前几天发布了ubuntu12.04LTS 版本,兴奋ing. 看到 ...