【发布时间】:2012-09-30 05:27:30
【问题描述】:
我已完成以下操作以使 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];
我希望它具有红色。我该怎么做?
【问题讨论】:
-
您为什么希望看到 2 种颜色?您的第二个 setValue: 调用只是替换了第一个,因为您正在设置相同键的值。
-
那么我该如何做才能看到不同链接的两种颜色呢?
标签: iphone objective-c ios ipad nimbus-ios