【发布时间】:2015-01-27 17:46:56
【问题描述】:
在我的代码中使用 TTTAttributedLabel:
NSString *contentText = @"some text here foo bar";
[self.content setText:contentText afterInheritingLabelAttributesAndConfiguringWithBlock:^NSMutableAttributedString *(NSMutableAttributedString *mutableAttributedString) {
return mutableAttributedString;
}];
self.content.linkAttributes = @{ NSForegroundColorAttributeName: [UIColor redColor],
NSUnderlineStyleAttributeName: [NSNumber numberWithInt:NSUnderlineStyleSingle] };
NSRange range = [self.content.text rangeOfString:@"foo bar"];
[self.content addLinkToURL:[NSURL URLWithString:@"action://load-foo"] withRange:range];
[self.content setNeedsDisplay];
在点击范围文本和执行操作方面,一切都很完美,但是,唯一似乎不起作用的是文本颜色。我是否在库中正确使用了NSForegroundColorAttributeName?
编辑:
“不起作用”是带下划线的文本保持灰色,而不是像我上面设置的那样为红色。
【问题讨论】:
-
您是否在低于 6 的 iOS 上进行部署?
-
@Andrea Nope,iOS8 及以上
-
使用 NSAttributeString 和默认文本渲染对象,用 UITextField 或 TextView 替换标签并检查数据检测器会容易得多
-
您应该在设置文本或向标签添加链接之前分配
linkAttributes。 -
这最后的评论实际上是正确的答案,谢谢
标签: ios objective-c tttattributedlabel