0

I have an editable UITextView, and if user prints text, containing an image link, I want that image to be opened in my second ViewController and not in a Safari web browser (as it is done by default).

How can I do it?

P.S. The UITextView behavior is set to "Selectable" and Data Detectors are set to "Link".

Emma V.
  • 89
  • 8

2 Answers2

0

So implement the textView(_:shouldInteractWith:in:interaction:) function, return FALSE, and then pass the URL to your second view controller, which would download and display the linked image.

Duncan C
  • 122,346
  • 22
  • 162
  • 258
0
@available(iOS 10.0, *)
func textView(_ textView: UITextView, shouldInteractWith URL: URL, in characterRange: NSRange, interaction: UITextItemInteraction) -> Bool {
     //... Handle URL action here ... //
    return false
}

and don't forget to add UITextViewDelegate

Shahrukh
  • 730
  • 9
  • 24