我正在使用UITextView,我想更改我在此组件中使用的超链接的颜色.例如,如果UITextView显示www.gmail.com,则显示为蓝色.我想改变那种颜色.
我正在尝试创建一个 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];
Run Code Online (Sandbox Code Playgroud)
但最终链接只有 UITextView 的色调颜色。是否可以使两个链接具有不同的颜色?提前致谢!
PS 如果可能的话,我不想使用库/框架。
UITextView上检测到的链接始终为蓝色.没有办法直接改变这个.但是我可以覆盖一些变蓝的过滤器,例如红色吗?