【发布时间】:2018-09-27 13:10:56
【问题描述】:
我正在尝试制作一个 UITextView 以在其中包含两个链接作为文本,但颜色不同。我不确定这是否可能。
我已将 UITextView 设置为检测链接,不可编辑,但只能选择。
到目前为止,我所做的如下:
NSMutableAttributedString *termsAndConditionsTitle = [[NSMutableAttributedString alloc] initWithString:@"I have read the " attributes:@{NSLinkAttributeName: @"https://apple.com", NSForegroundColorAttributeName: [UIColor greenColor]}];
NSMutableAttributedString *someString2 = [[NSMutableAttributedString alloc] initWithString:@"terms and conditions" attributes:@{NSLinkAttributeName: @"https://microsoft.com", NSForegroundColorAttributeName: [UIColor redColor]}];
[termsAndConditionsTitle appendAttributedString:someString2];
[self.termsAndConditionsView setAttributedText:termsAndConditionsTitle];
但最后链接只有 UITextView 的色调颜色。是否可以使两个链接具有不同的颜色?提前致谢!
附:如果可能,我不想使用库/框架。
【问题讨论】:
标签: ios objective-c hyperlink uitextview nsattributedstring