您的位置:首页 > 移动开发 > IOS开发

29. IOS系统原生富文本 自定义Label颜色

2015-09-01 17:20 453 查看
UILabel* lbl = [[UILabel alloc] init];

NSString* str = [NSString stringWithFormat:@"%@ %@", repeat, item.remember];

NSMutableAttributedString* aStr = [[NSMutableAttributedString alloc] initWithString:str];

[aStr addAttributes:[NSDictionary dictionaryWithObjectsAndKeys:

[UIFont systemFontOfSize:14],

NSFontAttributeName,

[UIColor blackColor],

NSForegroundColorAttributeName,

nil]

range:[str rangeOfString:repeat]];

[aStr addAttributes:[NSDictionary dictionaryWithObjectsAndKeys:

[UIFont systemFontOfSize:14],

NSFontAttributeName,

RGBCOLOR(188, 188, 188),

NSForegroundColorAttributeName,

nil]

range:[str rangeOfString:item.remember]];

lbl.attributedText = aStr;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: