iOS UIViewContentMode詳解

來源:互聯網
上載者:User

標籤:mode   orm   css   img   ping   測試   渲染   frame   text   

 

根據定義可以看出 UIViewContentMode 是UIView的屬性,所以這裡分別對UIImageView、UIView、UILabel、UIButton設定contentMode屬性來查看相應效果。

通過測試可以看到,contentMode屬性的設定,在視覺上只對UIImageView起作用,對UIView、UILabel、UIButton都不起作用。

對於UIView,因為它的子視圖都已經設定了自己的frame,位置是固定的,所以這裡contentMode不起作用。

對於UILabel、UIButton,並沒有像預期的一樣,通過設定不同的contentMode,而改變UILabel、UIButton中文本或圖片內容的填充樣式。

所以,對於contentMode屬性的主要探索就放在了UIImageView上。

先來看看測試過程中得到的所有:

 

 

 

 

typedef NS_ENUM(NSInteger, UIViewContentMode) {

 //預設樣式 圖片充滿整個輪廓,不按比例放大或縮小,圖片可能會變形

    UIViewContentModeScaleToFill,

 //圖片按比例放大或縮小,直到圖片和輪廓中相差比率較小的邊長度達到一致,圖片一定會展開,但不會變形

    UIViewContentModeScaleAspectFit,

 //圖片按比例放大或縮小,直到圖片和輪廓中相差比率較大的邊長度達到一致,圖片一定會展開,但不會變形

    UIViewContentModeScaleAspectFill,

 //調用setNeedsDisplay方法時,會重新渲染圖片,以下操作,圖片均不會被展開,不變形

    UIViewContentModeRedraw,

    UIViewContentModeCenter,

    UIViewContentModeTop,

    UIViewContentModeBottom,

    UIViewContentModeLeft,

    UIViewContentModeRight,

    UIViewContentModeTopLeft,

    UIViewContentModeTopRight,

    UIViewContentModeBottomLeft,

    UIViewContentModeBottomRight,

};

歡迎各路大神不吝指教、糾正~ 

iOS UIViewContentMode詳解

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.