Instance Method

textView(_:shouldInteractWith:in:)

Asks the delegate if the specified text view should allow user interaction with the given URL in the given range of text.

Declaration

optional func textView(_ textView: UITextView, shouldInteractWith URL: URL, in characterRange: NSRange) -> Bool

Parameters

textView

The text view containing the text attachment.

URL

The URL to be processed.

characterRange

The character range containing the URL.

Return Value

true if interaction with the URL should be allowed; false if interaction should not be allowed.

Discussion

The text view calls this method if the user taps or long-presses the URL link. Implementation of this method is optional. By default, the text view opens the application responsible for handling the URL type and passes it the URL. You can use this method to trigger an alternative action, such as displaying the web content at the URL in a web view within the current application.

See Also

Interacting with Text Data

func textView(UITextView, shouldInteractWith: NSTextAttachment, in: NSRange, interaction: UITextItemInteraction) -> Bool

Asks the delegate if the specified text view should allow the specified type of user interaction with the provided text attachment in the given range of text.

func textView(UITextView, shouldInteractWith: NSTextAttachment, in: NSRange) -> Bool

Asks the delegate if the specified text view should allow user interaction with the provided text attachment in the given range of text.

Deprecated
func textView(UITextView, shouldInteractWith: URL, in: NSRange, interaction: UITextItemInteraction) -> Bool

Asks the delegate if the specified text view should allow the specified type of user interaction with the given URL in the given range of text.