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| …
则通过截去显示照片