UILabel

// 设置标签显示文本
@property(nullable, nonatomic, copy) NSString *text;
// 设置文本字体和字体大小
@property(null_resetable, nonatomic, strong) UIFont *font;
// 设置文本颜色
@property(nullable, nonatomic, copy) UIColor *backgroundColor;
// 设置文本对齐方式,默认居左(NSTextAlignmentLeft)
@property(nonatomic) NSTextAlignment textAlignment;
// 设置超出label边界文字的截取方式(默认省略结尾)。
@property(nonatomic) NSLineBreakMode lineBreakMode;
// 设置文本是否可高亮
@property(nonatomic, getter=isHighlighted) BOOL highlighted;
// 设置用于渲染文本的最大行数。
@property(nonatomic) NSInteger numberOfLines;

UILable标签的创建

-(void)viewDidLoad {
    [super viewDidLoad];
    //
    UILabel *label = [[UIabel alloc] initWithFrame:CGRectMake(50, 100, 250, 50)];
    label.backgroundColor = [UIColor redColor];
    label.textColor = [UIColor whiteColor];
    label.text = @"www.csdn.com";
    label.font = [UIFont systemFontOfSize:20];
    label.textAlignment = NSTextAligenmentCenter;
    [self.view addSubview:label];
}
// 一个UILabel中显示不同的颜色或不同的字体文字。可以使用NSAttributedText和NSMutableAttributedText类,并设置UILabel的attributedText来实现上述效果.
-(void)viewDidLoad {
    [super viewDidLoad];
    //
    UILabel *label = [[UIabel alloc] initWithFrame:CGRectMake(20, 100, [UIScreen mainScreen].bounds.size.width-40, 30)];
    label.backgroundColor = [UIColor redColor];
    label.textColor = [UIColor whiteColor];
    label.text = @"www.csdn.com";
    label.font = [UIFont systemFontOfSize:20];
    label.textAlignment = NSTextAligenmentCenter;
    
    NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:label.text];
    [attributedString addAttribute:NSForegroundColorAttributeName value:[UIColor orangeColor] range:NSMakeRange(0, 4)];
    [attributedString addAttribute:NSFontgroundColorAttributeName value:[UIFont fontWithName:@"Arial-BoldItalicMT" size:30] range:NSMakeRange(0, 4)];
    [attributedString addAttribute:NSForegroundColorAttributeName value:[UIColor yellowColor] range:NSMakeRange(12, 5)];
    [attributedString addAttribute:NSFontgroundColorAttributeName value:[UIFont fontWithName:@"HelveticaNeue-Bold" size:25] range:NSMakeRange(12, 5)];
    label.attributedText = attributedString;

    [self.view addSubview:label];
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值