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 ...
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.