iOS - UILabel

UILabel變量
1. Text Attributes
@property(nullable, nonatomic,copy)   NSString           *text;            // default is nil   
 // 顯示的文本
@property(null_resettable, nonatomic,strong) UIFont      *font;            // default is nil (system font 17 plain)
// 要顯示文本的字體大小, 默認(rèn)17points
@property(nonatomic, copy) NSAttributedString *attributedText  
// 設(shè)置富文本 來代替 text
@property(nonatomic, strong) UIColor *textColor
// 文本的字體顏色, 若設(shè)置了attributedText的字體顏色,則會(huì)替代掉textColor 
@property(nonatomic) NSTextAlignment textAlignment
// 字體的對(duì)齊方式, 

typedef enum NSTextAlignment : NSUInteger {
NSTextAlignmentLeft = 0, // 居左對(duì)齊
NSTextAlignmentCenter = 1, // 居中對(duì)齊
NSTextAlignmentRight = 2, // 居右對(duì)齊
NSTextAlignmentJustified = 3, // 保證文本的最后是自然對(duì)齊
NSTextAlignmentNatural = 4, // 對(duì)齊方式遵循app設(shè)置
} NSTextAlignment;

@property(nonatomic)        NSLineBreakMode    lineBreakMode;   // default is NSLineBreakByTruncatingTail. used for single and multiple lines of text  
//  文本的截?cái)喾绞?,默認(rèn)是 NSLineBreakByTruncatingTail , 當(dāng)你設(shè)置styled text時(shí)候, 會(huì)代替掉這個(gè)方式

typedef NS_ENUM(NSInteger, NSLineBreakMode) {
NSLineBreakByWordWrapping = 0, // Wrap at word boundaries, default
NSLineBreakByCharWrapping, // Wrap at character boundaries
NSLineBreakByClipping, // Simply clip
NSLineBreakByTruncatingHead, // Truncate at head of line: "...wxyz"
NSLineBreakByTruncatingTail, // Truncate at tail of line: "abcd..."
NSLineBreakByTruncatingMiddle // Truncate middle of line: "ab...yz"
} NS_ENUM_AVAILABLE(10_0, 6_0);

@property(nonatomic, getter=isEnabled) BOOL enabled  // 這個(gè)屬性決定了這個(gè)label是如何繪制, disabled 表示變暗,處于不活躍狀態(tài)。默認(rèn)是yes

2. Sizing the Label’s Text
@property(nonatomic) BOOL adjustsFontSizeToFitWidth
// 一般情況下label 的text 會(huì)根據(jù)你設(shè)置的font來繪制,如果你把a(bǔ)djustsFontSizeToFitWidth屬性設(shè)置為yes, 則label會(huì)根據(jù)label的bounds和文本的長(zhǎng)度來設(shè)置字體的大小以適應(yīng)label的大小,直到你設(shè)置的minimum font size。

@property(nonatomic) UIBaselineAdjustment baselineAdjustment 
 // 當(dāng)adjustsFontSizeToFitWidth為yes時(shí),字體變動(dòng),baselineAdjustment 設(shè)置也隨之變動(dòng),默認(rèn)是UIBaselineAdjustmentAlignBaselines. 其作用僅僅是在 numberOfLines屬性設(shè)置為0的時(shí)候。
@property(nonatomic) CGFloat minimumScaleFactor
 // 最小字體尺寸
@property(nonatomic) NSInteger numberOfLines
// 最大文本的行數(shù), 默認(rèn)是1, 若設(shè)置成0則默認(rèn)無限制行數(shù)。

3.  Highlight Values
@property(nonatomic, strong) UIColor *highlightedTextColor
//當(dāng)highlighted設(shè)置為yes 的時(shí)候, 會(huì)顯示這個(gè)高亮色。
@property(nonatomic, getter=isHighlighted) BOOL highlighted
// 是否是高亮狀態(tài)默認(rèn)是 NO;

4. Drawing a Shadow
@property(nonatomic, strong) UIColor *shadowColor
// 默認(rèn)的陰影的顏色。默認(rèn)是nil,如果你不想用默認(rèn)的shadow,你需要改變shadowOffset這個(gè)屬性,
@property(nonatomic) CGSize shadowOffset
// 陰影偏移, 默認(rèn)是(0, -1)

5. Getting the Layout Constraints
@property(nonatomic) CGFloat preferredMaxLayoutWidth
// 當(dāng)布局約束應(yīng)用于它時(shí),這個(gè)屬性影響label的size。在布局中,如果文本超出這個(gè)preferredMaxLayoutWidth指定的寬度,多余的文本則會(huì)換行,從而增加標(biāo)簽的高度。

6. Setting and Getting Attributes
@property(nonatomic, getter=isUserInteractionEnabled) BOOL userInteractionEnabled
// 默認(rèn)時(shí)no, 表示無法交互。
@property(nonatomic) BOOL clipsToBounds
// 確定子視圖的范圍僅限于視圖。默認(rèn)是yes

7. Drawing and Positioning Overrides
- (CGRect)textRectForBounds:(CGRect)bounds limitedToNumberOfLines:(NSInteger)numberOfLines
 // 該方法只能被子類覆蓋,
 // bounds:The bounding rectangle of the receiver.
 // numberOfLines : The maximum number of lines to use for the label. The value 0 indicates there is no maximum number of lines and that the rectangle should encompass all of the text.

- (void)drawTextInRect:(CGRect)rect
// 繪制text區(qū)域, 你不應(yīng)該直接調(diào)用這個(gè)方法,這種方法只能被子類覆蓋。在你的覆蓋方法,你可以配置當(dāng)前上下文, 然后調(diào)用super或你自己進(jìn)行操作。如果你自己渲染文本,你不應(yīng)該super方法;
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

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

  • 創(chuàng)建:UILabel * label = [[UILabel alloc]initWithFrame:CGRect...
    fjytqiu閱讀 608評(píng)論 0 0
  • //創(chuàng)建uilabel UILabel *label1 = [[UILabel alloc] initWithFr...
    AAup閱讀 492評(píng)論 0 0
  • 家里養(yǎng)的第一只八哥久久一世剛來時(shí)也是雛鳥,不怕他會(huì)飛走就放心地讓他在家里閑逛。雖然是我和媽媽一起去花鳥市場(chǎng)把...
    左撇子的卓錦萬代閱讀 599評(píng)論 3 2
  • 音樂和下體一同升起我愛這音樂那頭的你 這兩句話是怎么來的? 聽網(wǎng)易云音樂時(shí),腦光一閃來的。 這兩句為什么好? 音樂...
    scort閱讀 380評(píng)論 1 1
  • 說實(shí)話,我真的不知道自己身上所存在的身體問題是否只是一點(diǎn)點(diǎn),我也不知道自己的壽命有多長(zhǎng),作為一個(gè)時(shí)常樂觀,時(shí)常悲觀...
    平凡不頻繁閱讀 366評(píng)論 0 1

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