首先看一下這個屬性
@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:圖片填充滿視圖,比例發(fā)生改變
UIViewContentModeScaleAspectFit:圖片都會在視圖里面顯示,并且比例不變啥辨。也就是說:如果圖片和視圖的比例不一樣,就會有留白
UIViewContentModeScaleAspectFill:整個視圖會被圖片填滿儡首,圖片比例不變 次兆,這樣圖片顯示就會大于視圖
UIViewContentModeCenter:保持視圖原比例以視圖中心點顯示圖片內(nèi)容
[圖片上傳中...(5.jpg-8e4f8b-1560770383790-0)]