我有这个代码
[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;}];并且只有第一个字符改变颜色,但文本的其余部分不改变。有什么想法吗?
发布于 2014-01-23 03:08:39
尝试:
[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)];发布于 2012-11-30 04:31:00
问题是我需要在每种颜色上都加上.CGRef,这是我的错
https://stackoverflow.com/questions/13631788
复制相似问题