首页 > 移动平台 > 详细

ios开发同一个lab显示不同的颜色

时间:2015-12-17 18:49:32      阅读:581      评论:0      收藏:0      [点我收藏+]

闲来无事自己把自己学的东西发表出来供大家使用学习。

UILabel *lab = [[UILabel alloc] initWithFrame:CGRectMake(100, 100, 200, 30)];

    [self.view addSubview:lab];

    NSMutableAttributedString *textStr = [[NSMutableAttributedString alloc] initWithString:@"红色黄色的,黑色"];

    [textStr addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(0, 2)];//从0位置开始的长度为2的红色

    [textStr addAttribute:NSForegroundColorAttributeName value:[UIColor yellowColor] range:NSMakeRange(2, 4)];//从2位置开始的长度为2的黄色的,

    [textStr addAttribute:NSForegroundColorAttributeName value:[UIColor blackColor] range:NSMakeRange(6, 2)];//从6位置开始的长度为2的黑色

    lab.attributedText = textStr;

ios开发同一个lab显示不同的颜色

原文:http://www.cnblogs.com/godlovexq/p/5054779.html

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