1
blankwonder 2015-04-11 12:56:38 +08:00
- (void)setTitleColor:(UIColor *)color forState:(UIControlState)state
|
2
lcl22hope OP @blankwonder 谢谢回答,这个方法我试过,它可以更改全部文字的颜色,但想只改变一部分,比如:备注1:hello world,“备注1:”部分想用绿色展示,但hello world用黑色
|
3
qq2511296 2015-04-11 13:27:46 +08:00 2
_label.text = @"备注1:hello world";
NSMutableAttributedString *attr = [[NSMutableAttributedString alloc]initWithString:_label.text]; [attr addAttribute:NSForegroundColorAttributeName value:[UIColor greenColor] range:[_label.text rangeOfString:@"备注1:"]]; [attr addAttribute:NSForegroundColorAttributeName value:[UIColor blackColor] range:[_label.text rangeOfString:@"hello world"]]; _label.attributedText = attr; |