UILabel 常用的属性
设置文字:
@property(nullable, nonatomic,copy) NSString *text; // default is nil
设置字体大小:
@property(null_resettable, nonatomic,strong) UIFont *font; // default is nil (system font 17 plain)
- 常用UIFont 类方法
+ (UIFont *)systemFontOfSize:(CGFloat)fontSize;
+ (UIFont *)boldSystemFontOfSize:(CGFloat)fontSize;
+ (UIFont *)italicSystemFontOfSize:(CGFloat)fontSize;
设置文字颜色:
@property(null_resettable, nonatomic,strong) UIColor *textColor; // default is nil (text draws black)
设置阴影颜色
@property(nullable, nonatomic,strong) UIColor *shadowColor; // default is nil (no shadow)
设置阴影位置
@property(nonatomic) CGSize shadowOffset; // default is CGSizeMake(0, -1) -- a top shadow
设置文字对齐方式
@property(nonatomic) NSTextAlignment textAlignment; // default is NSTextAlignmentLeft
- 是一个枚举
typedef NS_ENUM(NSInteger, NSTextAlignment) {
NSTextAlignmentLeft = 0, // Visually left aligned
#if TARGET_OS_IPHONE
NSTextAlignmentCenter = 1, // Visually centered
NSTextAlignmentRight = 2, // Visually right aligned
#else /* !TARGET_OS_IPHONE */
NSTextAlignmentRight = 1, // Visually right aligned
NSTextAlignmentCenter = 2, // Visually centered
#endif
NSTextAlignmentJustified = 3, // Fully-justified. The last line in a paragraph is natural-aligned.
NSTextAlignmentNatural = 4, // Indicates the default alignment for script
} NS_ENUM_AVAILABLE_IOS(6_0);
设置断行方式
@property(nonatomic) NSLineBreakMode lineBreakMode;
- NSTextAlignment 这是一个枚举
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"
@property(nullable,nonatomic,copy) NSAttributedString*attributedTextNS_AVAILABLE_IOS(6_0);// default is nil
设置高亮文字颜色
@property(nullable,nonatomic,strong) UIColor*highlightedTextColor;// default is nil
是否高亮文字
@property(nonatomic,getter=isHighlighted)BOOL highlighted;// default is NO
以下的不怎么用到以后补充
@property(nonatomic,getter=isUserInteractionEnabled)BOOLuserInteractionEnabled;// default is NO
@property(nonatomic,getter=isEnabled)BOOLenabled; // default is YES. changes how the label is drawn
// this determines the number of lines to draw and what to do when sizeToFit is called. default value is 1 (single line). A value of 0 means no limit
// if the height of the text reaches the # of lines or the height of the view is less than the # of lines allowed, the text will be
// truncated using the line break mode.
@property(nonatomic)NSIntegernumberOfLines;
// these next 3 property allow the label to be autosized to fit a certain width by scaling the font size(s) by a scaling factor >= the minimum scaling factor
// and to specify how the text baseline moves when it needs to shrink the font.
@property(nonatomic)BOOLadjustsFontSizeToFitWidth; // default is NO
@property(nonatomic)UIBaselineAdjustmentbaselineAdjustment;// default is UIBaselineAdjustmentAlignBaselines
@property(nonatomic)CGFloatminimumScaleFactorNS_AVAILABLE_IOS(6_0);// default is 0.0
// Tightens inter-character spacing in attempt to fit lines wider than the available space if the line break mode is one of the truncation modes before starting to truncate.
// The maximum amount of tightening performed is determined by the system based on contexts such as font, line width, etc.
@property(nonatomic)BOOLallowsDefaultTighteningForTruncationNS_AVAILABLE_IOS(9_0);// default is NO
// override points. can adjust rect before calling super.
// label has default content mode of UIViewContentModeRedraw
(CGRect)textRectForBounds:(CGRect)bounds limitedToNumberOfLines:(NSInteger)numberOfLines;
(void)drawTextInRect:(CGRect)rect;
// Support for constraint-based layout (auto layout)
// If nonzero, this is used when determining -intrinsicContentSize for multiline labels
@property(nonatomic)CGFloatpreferredMaxLayoutWidthNS_AVAILABLE_IOS(6_0);
// deprecated:
@property(nonatomic)CGFloatminimumFontSizeNS_DEPRECATED_IOS(2_0,6_0)__TVOS_PROHIBITED;// deprecated - use minimumScaleFactor. default is 0.0
// Non-functional. Hand tune by using NSKernAttributeName to affect tracking, or consider using the allowsDefaultTighteningForTruncation property.
@property(nonatomic)BOOLadjustsLetterSpacingToFitWidthNS_DEPRECATED_IOS(6_0,7_0)__TVOS_PROHIBITED;