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,
};
UIViewContentMode不是有很多种吗,记住 几个要点就可以很容易记住都分别是什么样的状态了。
- 1.带有scale的会被拉伸
- 2.带有Aspect会保持原来的比例
- 3.fit是保证大小在合适的范围,即能宽和高至少有一个是和边框的宽高一致的
- 4.fill是要充满边框,所以可能会导致最后宽或者高超出边框范围,这个时候就clipsToBounds就可以了
- 5.UIViewContentModeRedraw, // redraw on bounds change (calls -setNeedsDisplay)这个是调用setNeedsDisplay这个方法时会重新画一遍