访问文本属性:
1.设置标签文本:
@property(nonatomic, copy) NSString *text
2.显示文字,为(NSAttributedString类型):
@property(nonatomic, copy) NSAttributedString *attributedText
3.设置标签文本字体和大小:
@property(nonatomic, retain) UIFont *font
例如:
label1.font = [UIFont fontWithName:@"Arial" size:30];
加粗并且倾斜:
loginLabel.font
@property(nonatomic, retain) UIColor *textColor
5.设置文本对齐方式:
@property(nonatomic) NSTextAlignment textAlignment
enum {
NSTextAlignmentLeft = 0,
NSTextAlignmentCenter = 1,
NSTextAlignmentRight = 2,
NSTextAlignmentJustified = 3,
NSTextAlignmentNatural = 4,
};
typedef NSInteger NSTextAlignment;
6.文字超出label边界的截取方式:
@property(nonatomic) NSLineBreakMode lineBreakMode
enum {
NSLineBreakByWordWrapping = 0,
NSLineBreakByCharWrapping ,
NSLineBreakByClipping ,
NSLineBreakByTruncatingHead ,
NSLineBreakByTruncatingTail ,
NSLineBreakByTruncatingMiddle
};
typedef NSUInteger NSLineBreakMode
7.文本是否可变:
@property(nonatomic, getter=isEnabled) BOOL enabled
加工标签文本:
8.是否根据文本宽度改变字体大小(自适应):
@property(nonatomic) BOOL adjustsFontSizeToFitWidth
9.改变字母之间的间距来适应label大小(iOS7.0不建议使用):
@property(nonatomic) BOOL adjustsLetterSpacingToFitWidth
当这个属性是YES,标签可能改变标签文本的字母间距,以使该文本更适合标签的边界内。此属性的字符串,而不管当前行的行的裁剪模式。该属性的默认值是NO。
10.控制文本的基线位置,只有文本行数为1时有效:
@property(nonatomic) UIBaselineAdjustment baselineAdjustment
typedef enum {
UIBaselineAdjustmentAlignBaselines ,//默认值 文本最上端于label中线对齐
UIBaselineAdjustmentAlignCenters ,//文本中线于 label中线对齐
UIBaselineAdjustmentNone ,//文本最低端与label中线对齐
} UIBaselineAdjustment;
11.当前字体大小(默认为0):
@property(nonatomic) CGFloat minimumScaleFactor
12.最小字体大小,当字体小于这个最小值时无效(iOS6.0以后不建议使用):
@property(nonatomic) CGFloat minimumFontSize
13.文本最多行数,为0时没有最大行数限制:
@property(nonatomic) NSInteger numberOfLines
突出显示值管理:
14.高亮颜色:
@property(nonatomic, retain) UIColor *highlightedTextColor
15.文本是否高亮:
@property(nonatomic, getter=isHighlighted) BOOL highlighted
绘制阴影:
16.文本阴影颜色(默认为nil):
@property(nonatomic, retain) UIColor *shadowColor
17.阴影大小:
@property(nonatomic) CGSize shadowOffset
例如:
label1.shadowOffset = CGSizeMake(1.0, 1.0);
重写绘图和定位:
18.计算UIlabel随字体多行后的高度:
- (CGRect)textRectForBounds:(CGRect)bounds
limitedToNumberOfLines:(NSInteger)numberOfLines
例如:
CGRect result,bounds;
bounds = CGRectMake(0,0,200, 300);
heightLabel = [myLabel textRectForBounds:bounds
limitedToNumberOfLines:20];//计算20行后的Label的Frame
NSLog(@"%f",heightLabel.size.height);
19.绘制文本到指定区域:
- (void)drawTextInRect:(CGRect)rect
需要重载此方法,然后由子类调用,重写时调用super可以按默认图形属性绘制,若自己完全重写绘制函数,就不用调用super了。
获取和设置属性:
20.能否与用户交互:
@property(nonatomic, getter=isUserInteractionEnabled) BOOL userInteractionEnabled
布局约束:
21.优先选择标签布局的最大宽度:
@property(nonatomic) CGFloat preferredMaxLayoutWidth