【发布时间】:2014-03-18 16:06:23
【问题描述】:
我有一个显示推文的 UITextView。一些推文有标签。我在 StackOverflow 上找到了一个很好的答案,它允许我识别主题标签,然后对其应用颜色。然而,我的 UITextView 的属性文本属性没有被应用....由于某种原因。这是我的代码:
NSString *message = final_data[index];
NSArray *words = [message componentsSeparatedByString:@" "];
NSMutableAttributedString *attrString = [[NSMutableAttributedString alloc] initWithString:message];
for (NSString *word in words) {
if ([word hasPrefix:@"#"]) {
NSRange matchRange = [message rangeOfString:word];
[attrString addAttribute:(__bridge NSString *)kCTForegroundColorAttributeName value:[UIColor blueColor] range:matchRange];
}
}
cell_tw.message_post.attributedText = attrString;
“message_post”是我的 UITableview 中自定义单元格中的 UITextView。
尽管属性文本属性的全部意义在于您可以设置这些类型的设置,例如文本颜色。
这里出了什么问题?
【问题讨论】:
标签: ios cocoa-touch text uicolor hashtag