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方法;