首先看一下这个属性
@property(nonatomic) UIViewContentMode contentMode; // default is UIViewContentModeScaleToFill
然后看一下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:图片填充满视图,比例发生改变
UIViewContentModeScaleAspectFit:图片都会在视图里面显示,并且比例不变。也就是说:如果图片和视图的比例不一样,就会有留白
UIViewContentModeScaleAspectFill:整个视图会被图片填满,图片比例不变 ,这样图片显示就会大于视图
UIViewContentModeCenter:保持视图原比例以视图中心点显示图片内容
[图片上传中...(5.jpg-8e4f8b-1560770383790-0)]