0

我有这个代码

[label setText:@"ddddasdasdas" afterInheritingLabelAttributesAndConfiguringWithBlock:^ NSMutableAttributedString *(NSMutableAttributedString *mutableAttributedString) {
            [mutableAttributedString addAttribute:(NSString*)kCTForegroundColorAttributeName value:(id)[UIColor blackColor] range:NSMakeRange(0,1)];
            [mutableAttributedString addAttribute:(NSString*)kCTForegroundColorAttributeName value:(id)[UIColor redColor] range:NSMakeRange(2,3)];
            [mutableAttributedString addAttribute:(NSString*)kCTForegroundColorAttributeName value:(id)[UIColor greenColor] range:NSMakeRange(5,2)];
            return mutableAttributedString;}];

并且只有第一个字符改变颜色,但其余文本没有改变。有任何想法吗?

4

2 回答 2

0

尝试:

[mutableAttributedString addAttribute:(NSString*)kCTForegroundColorAttributeName value:(id)[[UIColor blackColor] CGColor] range:NSMakeRange(0,1)];

或者:

[mutableAttributedString addAttribute:(NSString*)NSForegroundColorAttributeName value:(id)[[UIColor blackColor] CGColor] range:NSMakeRange(0,1)];
于 2014-01-22T19:08:39.453 回答
-1

问题是我需要在每种颜色上加上 .CGRef,我的错

于 2012-11-29T20:30:59.903 回答