一、? contentMode
public enum UIViewContentMode : Int {
case scaleToFill??
case scaleAspectFit // contents scaled to fit with fixed aspect. remainder is transparent
case scaleAspectFill // contents scaled to fill with fixed aspect. some portion of content may be clipped.
case redraw // redraw on bounds change (calls -setNeedsDisplay)
case center // contents remain same size. positioned adjusted.
case top
case bottom
case left
case right
case topLeft
case topRight
case bottomLeft
case bottomRight
}
二、scaleToFill? 、 scaleAspectFit 、 scaleAspectFill
1、scaleToFill
Scales the content to fit the size of itself by changing the aspect ratio of the content if necessary.
Scale To Fill那個圖片顯然一張212 * 80 的圖片要放到 100 * 100的視圖中,要做的就是寬(212)要縮小到100,高(80)要放大到100,有點感覺像把圖片在水平方向擠壓似的。
2、scaleAspectFit
Scales the content to fit the size of the view by maintaining the aspect
ratio. Any remaining area of the view’s bounds is transparent.
Aspect Fit這個圖片顯示真應了fit這個單詞,通過放縮將(212,80)圖片放入(100,100)的View中這個不用說,問題是與上面的放縮不同在于,它的寬高都是使用同一比例,寬212 * 0.4717 = 100,與上面不同,高80 * 0.4717 = 37.74,所以圖片很真實,盡管縮小了0.4717比率
3、scaleAspectFill
Scales the content to fill the size of the view. Some portion of the content may be clipped to fill the view’s bounds.
Aspect Fill這個就應了Fill單詞了,它和Fit不同,要把小的(也就是高80)放大起到填充的感覺,也就是80 * 1.25 = 100 那么我們的寬212,也要乘以1.25 = 265,最后得到一個(265,100)的圖片,而我們的框框是(100,100),顯然我們的視圖顯示圖片余地有限,因此只能顯示中間那一部分了。