ios

iOS Scale to Fill,Aspect Fit,A

2017-10-12  本文已影响72人  铅笔人生

一、  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),显然我们的视图显示图片余地有限,因此只能显示中间那一部分了。

上一篇下一篇

猜你喜欢

热点阅读