作者热门文章
- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我已完成以下操作以在我的 NIAttributedLabel 中为链接设置不同的颜色:
NSMutableDictionary *attributes = [NSMutableDictionary dictionary];
[attributes setValue:[UIColor colorWithRed:86.0/255.0 green:134.0/255.0 blue:172.0/255.0 alpha:1.0] forKey:NSForegroundColorAttributeName];
[attributes setValue:[UIColor colorWithRed:0.0 green:136/255.f blue:204/255.f alpha:1.0] forKey:NSForegroundColorAttributeName];
[self.commentsText_ setAttributesForLinks:attributes];
但我没有在链接中看到两种不同的颜色,而是只看到一种。我在这里做错了什么?基本上我有一个通过 addLink 添加的链接,如下所示:
[self.commentsText_ addLink:[NSURL URLWithString:url] range:usernameRange];
我希望它具有红色。我该怎么做?
最佳答案
如果你想为不同的链接使用不同的颜色,那么你需要创建单独的属性字典,并调用 setAttributesForLinks: 使用不同的字典。
NSMutableDictionary *attributes1 = [NSMutableDictionary dictionary];
[attributes setValue:[UIColor colorWithRed:86.0/255.0 green:134.0/255.0 blue:172.0/255.0 alpha:1.0] forKey:NSForegroundColorAttributeName];
[self.commentsText1_ setAttributesForLinks:attributes1];
NSMutableDictionary *attributes2 = [NSMutableDictionary dictionary];
[attributes setValue:[UIColor colorWithRed:0.0 green:136/255.f blue:204/255.f alpha:1.0] forKey:NSForegroundColorAttributeName];
[self.commentsText2_ setAttributesForLinks:attributes2];
关于iphone - 在 NIAttributedLabel 中为链接设置属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12658896/
我正在尝试使用NIAttributedLabel来生成同时具有文本,链接和支持此行为的标签: 按链接将调用- (void)attributedLabel:(NIAttributedLabel *)at
我已完成以下操作以在我的 NIAttributedLabel 中为链接设置不同的颜色: NSMutableDictionary *attributes = [NSMutableDictionary d
我正在使用 NIAttributedLabel 在文本上显示链接。 NIAttributedLabel *label; label = [[NIAttr
我已经浏览了 SO 上关于此方法的每一篇文章的感觉。许多海报的答案都是设置一个非常大的值作为高度约束。 但是,对我来说这不起作用。这是我的代码: //Create the contentLabel L
我是一名优秀的程序员,十分优秀!