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.
  • 99
  • 1
  • 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
  • 128,072
  • 22
  • 173
  • 272
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
  • 740
  • 7
  • 25