UIImageView学习笔记

12th,September,2016

ContentMode

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,
};

UIViewContentModeScaleToFill

比如显示一张图片在一个正方形中,如果图片规格为200*400,那么显示时则会变形.

UIViewContentModeScaleAspectFit

如果照片规格为200*400,显示时会通过留白的方式按比例显示照片。

UIViewContentModeScaleAspectFill

按比例显示图片,显示不会变形,但如果图片规格为200*400,则显示时会超出ImageView的显示范围。 不过可以通过设置clipsToBounds属性为YES时,则会对视图进行裁剪使其在ImageView的显示范围内。ps: 200*400,左右超出显示范围; 500*200,则上下超出显示范围;

UIViewContentModeRedraw

视图的尺寸位置发生变化的时候通过调用setNeedsDisplay方法来重新显示,如未在该方法中做一定实现,默认显示跟UIViewContentModeScaleAspectFill类似.

UIViewContentModeCenter

保持图片原比例在视图中间显示图片内容,如果图片比较大则可能会超出视图范围.

UIViewContentModeTop|Bottom|Left| …

则通过截去显示照片

参考资料

iOS图片填充UIImageView(contentMode)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值