iOS開發項目篇—10對齊

來源:互聯網
上載者:User

標籤:des   style   color   strong   os   io   

iOS開發項目篇—10對齊

一、關於四個容易混淆屬性的對比說明

1. textAligment : 文字的水平方向的對齊

(1) 取值

NSTextAlignmentLeft      = 0,    // 靠左對齊

NSTextAlignmentCenter    = 1,    // 置中對齊

NSTextAlignmentRight    = 2,    // 靠右對齊

 

(2) 哪些控制項有這個屬性 : 一般能夠顯示文字的控制項都有這個屬性

* UITextField

* UILabel

* UITextView

 

2. contentVerticalAlignment : 內容的垂直方向的對齊

(1) 取值

UIControlContentVerticalAlignmentCenter  = 0, // 置中對齊

UIControlContentVerticalAlignmentTop     = 1, // 頂部對齊

UIControlContentVerticalAlignmentBottom  = 2, // 底部對齊

 

(2)哪些控制項有這個屬性 : 繼承自UIControl的控制項或者UIControl本身

* UIControl

* UIButton

* UITextField

 

3. contentHorizontalAlignment : 內容的水平方向的對齊

(1)取值

UIControlContentHorizontalAlignmentCenter = 0, // 置中對齊

UIControlContentHorizontalAlignmentLeft   = 1, // 靠左對齊

UIControlContentHorizontalAlignmentRight  = 2, // 靠右對齊

 

(2)哪些控制項有這個屬性 : 繼承自UIControl的控制項或者UIControl本身

* UIControl

* UIButton

* UITextField

 

4. contentMode : 內容模式(控制內容的對齊), 一般對UIImageView很有用

(1) 取值

 規律:

 1.Scale : 圖片會展開

 2.Aspect : 圖片會保持原來的寬高比

 

 前3個情況, 圖片都會展開

(預設)展開圖片至填充整個UIImageView(圖片的顯示尺寸會跟UIImageView的尺寸一樣)

UIViewContentModeScaleToFill,

按照圖片原來的寬高比進行伸縮, 伸縮至適應整個UIImageView(圖片的內容不能超出UIImageView的尺寸範圍)

UIViewContentModeScaleAspectFit,

 按照圖片原來的寬高比進行伸縮, 伸縮至 圖片的寬度和UIImageView的寬度一樣 或者 圖片的高度和UIImageView的高度一樣

UIViewContentModeScaleAspectFill,

後面的所有情況, 都會按照圖片的原來尺寸顯示, 不會進行展開

UIViewContentModeRedraw,  // 當控制項的尺寸改變了, 就會重繪一次(重新調用setNeedsDisplay, 調用drawRect:)

UIViewContentModeCenter,

UIViewContentModeTop,

UIViewContentModeBottom,

UIViewContentModeLeft,

UIViewContentModeRight,

UIViewContentModeTopLeft,

UIViewContentModeTopRight,

UIViewContentModeBottomLeft,

UIViewContentModeBottomRight,

(2) 哪些控制項有這個屬性 : 所有UI控制項都有 

5. 如果有多個屬性的作用衝突了, 只有1個屬性有效(就近原則)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.