设置NSLinkAttributeName字体颜色

Ore*_*ren 21 ios nsmutableattributedstring

我觉得我错过了一些简单的东西,但我似乎无法找到如何做到这一点:

我将属性设置为如下链接:

[myAttrString addAttribute:NSLinkAttributeName value:linkURL range:selectedRange];
Run Code Online (Sandbox Code Playgroud)

这是有效的,但链接是蓝色的,我似乎无法改变颜色.这将除了链接之外的所有内容设置为白色

[myAttrString addAttribute:NSForegroundColorAttributeName value:[UIColor whiteColor] range:selectedRange];
Run Code Online (Sandbox Code Playgroud)

是否有其他颜色属性名称,我似乎无法找到特定于链接?

Jus*_*ser 63

  1. 用一个 UITextView
  2. 设置UITextViewlinkTextAttributes,像这样:

    textView.linkTextAttributes = @{NSForegroundColorAttributeName:[UIColor whiteColor]};
    
    Run Code Online (Sandbox Code Playgroud)

  • 这个答案有效但只有你可以绑定到UITextView.对UILabel不起作用. (8认同)
  • 这个问题是关于NSAttributedString,而不是UITextView (4认同)