我正在使用 UITextView 来使主题标签可选。它可以完美地检测水龙头。我的问题是选择颜色。它看起来是黑色的,我希望文本在选择时稍微褪色。 这是我现在得到的:
我尝试更改 tintColor
、NSForegroundColorAttributeName
和 NSBackgroundColorAttributeName
,但不起作用。
最佳答案
检测到的链接的选定或突出显示颜色没有记录属性,但您应该能够通过重写委托(delegate)方法 textView:shouldInteractWithURL:inRange:
并更改颜色来实现相同的效果你自己。
来自UITextViewDelegate协议(protocol)引用:
The text view calls this method if the user taps or long-presses the URL link. Implementation of this method is optional. By default, the text view opens the application responsible for handling the URL type and passes it the URL. You can use this method to trigger an alternative action, such as displaying the web content at the URL in a web view within the current application.
最后一个参数是一个名为 characterRange
的 NSRange 对象,它表示包含点击的 URL(或主题标签)的字符范围。使用该范围,您应该能够添加诸如 NSForegroundColorAttributeName
之类的属性,以便仅更改所点击的特定主题标签的颜色。
您可能希望恢复对 touchesEnded
和 touchesCancelled
的任何更改。
或者,您可以 make your own subclass and manually handle the above .
关于ios - 如何更改 UITextView 超链接选择背景颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36596010/