iOS Scale to Fill,Aspect Fit,Aspect Fill

一、? 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),顯然我們的視圖顯示圖片余地有限,因此只能顯示中間那一部分了。

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容

  • **2014真題Directions:Read the following text. Choose the be...
    又是夜半驚坐起閱讀 9,934評論 0 23
  • 一個人會落淚,是因為痛;一個人之所以痛,是因為在乎;一個人之所以在乎,是因為有感覺;一個人之所以有感覺,僅因為你是...
    莣清閱讀 216評論 2 2
  • 喜鵲,忙碌著搭一座愛之橋,不顧疲倦。只為了成全,這一年一度,七夕相逢。 千百年來,織女的淚,牛郎的痛,有誰懂?一條...
    金釵銀環閱讀 540評論 0 17
  • 今天感恩自己參加了初心活動的線下活動。 感恩認識了一幫90后,哈哈,讓我知道,我跟他們居然沒代溝。 感恩訓導主任指...
    米勒Li閱讀 137評論 0 0
  • heartsense 三色堇。而三色堇的花語是思慮,妙的是這個單詞也意為心平氣和。 如果有思慮,就不可能心平氣和啦...
    燈燈007閱讀 1,721評論 6 0