首页 > 其他 > 详细

label 不同颜色

时间:2016-08-12 11:26:16      阅读:132      评论:0      收藏:0      [点我收藏+]

label  不同颜色

UILabel* noteLabel = [[UILabel alloc] init];

    noteLabel.frame = CGRectMake(60, 100, 200, 100);

    noteLabel.textColor = [UIColor blackColor];

    noteLabel.numberOfLines = 2;

    

    NSMutableAttributedString *noteStr = [[NSMutableAttributedString alloc] initWithString:@"点击注册按钮,即表示您已同意隐私条款和服务协议"];

    NSRange redRange = NSMakeRange([[noteStr string] rangeOfString:@"注册"].location, [[noteStr string] rangeOfString:@"注册"].length);

    [noteStr addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:redRange];

 

    NSRange redRangeTwo = NSMakeRange([[noteStr string] rangeOfString:@"同意"].location, [[noteStr string] rangeOfString:@"同意"].length);

    [noteStr addAttribute:NSForegroundColorAttributeName value:[UIColor greenColor] range:redRangeTwo];

   

    [noteLabel setAttributedText:noteStr];

    [noteLabel sizeToFit];

    [self.view addSubview:noteLabel];

label 不同颜色

原文:http://www.cnblogs.com/zuidap/p/5764086.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!