Setting NSLinkAttributeName font color

Oren picture Oren · Aug 23, 2014 · Viewed 13.8k times · Source

I feel like I'm missing something easy but I can't seem to find out how to do this:

I set the attribute to a link like so:

[myAttrString addAttribute:NSLinkAttributeName value:linkURL range:selectedRange];

That works but the link is blue and I can't seem to change the color. This sets everything except the link to white:

[myAttrString addAttribute:NSForegroundColorAttributeName value:[UIColor whiteColor] range:selectedRange];

Is there another color attribute name that I can't seem to find that is specific to links?

Answer

Justin Moser picture Justin Moser · Sep 4, 2014
  1. Use a UITextView
  2. Set the UITextView's linkTextAttributes like so:

    textView.linkTextAttributes = @{NSForegroundColorAttributeName:[UIColor whiteColor]};