UILabel简介

访问文本属性:

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 = [UIFont fontWithName:@"Helvetica-BoldObliquesize:20];


4.文本颜色:

@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


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值