3

enter image description here

I want to clear that gray selection box when I clicked the link but I still cannot find the solution. Therefore, I'm trying to change the selection color according to How to change UITextView Hyperlink selection background color?

I don't want to use private API suggestion, so I used textView:shouldInteractWithURL:inRange:. However, so far I got ... enter image description here

func textView(_ textView: UITextView, shouldInteractWith URL: URL, in characterRange: NSRange) -> Bool {
    textView.textStorage.beginEditing()
    textView.textStorage.addAttribute(.backgroundColor, value: UIColor.white, range: characterRange)
    textView.textStorage.addAttribute(.foregroundColor, value: UIColor.white, range: characterRange)
    textView.textStorage.endEditing()

    return true
}

I have no idea how to eliminate the gray frame. I also looked at attributes in NSAttributedStringKey, but still have no clue.

R.Wonder
  • 151
  • 2
  • 8

1 Answers1

-2

You have two options or you may need to implement both, depending on what you're looking for.

Try inserting:

textView.tintColor = UIColor.clear

and/or

textView.backgroundColor = UIColor.clear

..into your method.

Hope that helps.

Super_Simon
  • 1,250
  • 8
  • 25