【发布时间】:2017-04-02 12:23:30
【问题描述】:
我想在 UITextView 或 UILabel 中为每个链接设置不同的样式。我目前正在使用带有链接的 UITextViews,但我希望 URL 显示为紫色,用户名显示为黑色。我也查看了 TTTAttributedLabel,但似乎无法找到如何完成此操作。
textView.linkTextAttributes = [NSForegroundColorAttributeName: UIColor.orange]
attributedString.setAttributes([NSLinkAttributeName: url, range: range)
attributedString.addAttributes([NSForegroundColorAttributeName: UIColor.purple], range: range)
在上面的示例中,这是我尝试过的,链接将是橙色的,而不是紫色的。如果我不设置 linkTextAttributes,链接将是蓝色的。如何使用每个链接的不同属性覆盖 linkTextAttributes?
【问题讨论】:
-
谢谢,但是我已经尝试过linkTextAttributes。我的问题是关于每个链接的不同属性。事实上,我的问题是在您的第一个链接的评论中提出的,但没有给出答案stackoverflow.com/questions/28361072/…@RenatoIoshida
标签: ios swift hyperlink uitextview nsattributedstring