標籤:
四個容易混淆的屬性:
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個屬性有效(就近原則)
[iOS微博項目 - 1.3] - 內容對齊 TextAlignment & VerticalAlignment & HorizontalAlignment & contentMode