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

UIImageView 的contentMode属性知识点回顾

2016-08-02 16:18 337 查看
(1)定义如下:

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, 视图右下角对齐
};


(2)小记

<1>上述枚举常量中只要是不带Scale的,当图片尺寸超过 ImageView尺寸时,只有部分显示在ImageView中。

<2> 有scale必定会伸缩,但是有aspect时,一定会按照原来的宽高比去伸缩。

<3> UIViewContentModeScaleToFill属性是UIViewContentMode的默认属性,会导致图片变形,即让图片按照整个区域进行拉伸(会破坏图片的比例)。

<4> UIViewContentModeScaleAspectFit将图片等比例拉伸,而且全部显示在ImageView中,但可能不会填充满整个区域,即ImageView会有部分空白。

<5> UIViewContentModeScaleAspectFill将图片等比例拉伸,会填充整个ImageView区域,但是会有一部分过大而超出整个区域,所以可能只有部分图片显示出来。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  uiimageview