UIImageView圖片自適應(yīng)

UIImageView的ContentMode的這些參數(shù),這些參數(shù)一般就能滿分我們的開發(fā)需求

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:圖片拉伸至填充這個UIImageView(圖片可能變形)

轉(zhuǎn)載自 http://www.myexception.cn/mobile/2052661.html


UIViewContentModeScaleAspectFit : 圖片拉伸至完全顯示在UIImageView里面為止(圖片不會變形)

UIViewContentModeScaleAspectFill : 圖片拉伸至 圖片的寬度等于UIImageView的寬度 或者 圖片的高度等于UIImageView的高度為止,然后將圖片居中顯示

UIViewContentModeRedraw : 調(diào)用了setNeedsDisplay方法時,就會將圖片重新渲染

UIViewContentModeCenter:居中顯示

。。。。別的跟這個也是一樣的了,用的少

我們還可以設(shè)置超出邊框的內(nèi)容都剪掉:

topView.clipsToBounds = YES;

總結(jié)一下:

凡是帶有Scale單詞的,圖片都會拉伸

凡是帶有Aspect單詞的,圖片都會保持原來的寬高比,圖片不會變形

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容