首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >TTTAttributedLabel多色

TTTAttributedLabel多色
EN

Stack Overflow用户
提问于 2012-11-30 01:55:10
回答 2查看 1.1K关注 0票数 0

我有这个代码

代码语言:javascript
复制
[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;}];

并且只有第一个字符改变颜色,但文本的其余部分不改变。有什么想法吗?

EN

回答 2

Stack Overflow用户

发布于 2014-01-23 03:08:39

尝试:

代码语言:javascript
复制
[mutableAttributedString addAttribute:(NSString*)kCTForegroundColorAttributeName value:(id)[[UIColor blackColor] CGColor] range:NSMakeRange(0,1)];

或者:

代码语言:javascript
复制
[mutableAttributedString addAttribute:(NSString*)NSForegroundColorAttributeName value:(id)[[UIColor blackColor] CGColor] range:NSMakeRange(0,1)];
票数 0
EN

Stack Overflow用户

发布于 2012-11-30 04:31:00

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

票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13631788

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档