1

I'd like to be able to show a UITextView that has multi-colored hyperlinks (ie, some hyperlinks red, some blue, some green, etc.)

No matter what I set NSForegroundColorAttributeName to for the given range of the hyperlink it always seems to get overwritten by whatever is specified in myTextView.linkTextAttributes.

Is there a way I can disable the linkTextAttributes functionality or override its styles on a per-range basis?

Albert Bori
  • 9,832
  • 10
  • 51
  • 78
  • 1
    Have you try disabling automatic data detection? – Losiowaty Apr 11 '17 at 19:39
  • @Losiowaty Does that prevent automatic link detection (and therefore `shouldInteractWithURL` delegate calls)? – Albert Bori Apr 11 '17 at 19:48
  • I'm not sure, but probably yes - there are solutions to this (i.e. http://stackoverflow.com/questions/19332283/detecting-taps-on-attributed-text-in-a-uitextview-in-ios ) though. This requires some extra logic to be written. There are also some links in the linked thread about TextKit, which might also be a good place to take a look at. – Losiowaty Apr 11 '17 at 19:53
  • UITextView supports HTML, you could use that to format text however you want. – The Dreams Wind Apr 11 '17 at 20:17

1 Answers1

0

Expected result

You can find my full tutorial about multiple hyperlink colors here: https://octodev.net/changing-uitextview-hyperlink-color/

Tutorial contains implementation in both languages: Swift and Objective-C.

Would be more than glad to answer all your questions.

  • 2
    Hi, please avoid posting links to external tutorials. If you have a valid solution you should **cite** the source and a link to it. – Noel Widmer May 18 '17 at 18:41
  • Unfortunately, in this case it's not possible to describe a solution just briefly. I've attached exact and full solution for mentioned problem. – Dmytro Brovkin May 19 '17 at 11:44