使用 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
是否正确使用了库?
编辑:
“不起作用”是带下划线的文本保持灰色,而不是像我在上面设置的那样是红色的。