UIViewContentMode 是UIImageView的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填充整个imageView并完全显示, 但是会导致图片变形.
UIViewContentModeScaleAspectFit图片比例不变并全部显示,但是会导致imageView留有空白.
UIViewContentModeScaleAspectFill图片比例不变并将imageView全部覆盖,但是会导致部分内容显示不出来.