How to click url / email address / phone number in UITextView

I get the server response as a sting, which may contain some URL or email address or phone number, i.e. the same line can contain all three or one number and a couple of URLs. Nothing is fixed.

I use UITextView to show this sting on the device. Now I want this URL / phone / email number to display as a hyperlink, and when I click on this hyperlink, the user should be able to see the web page if its URL, draft and send an email if its email address mail or call the number when you click the hyperlink number

Can anyone suggest me a way to do this. Or suggest any other kind of data that will be used to make your task easier.

+5
source share
3 answers

Set the types of your data detectors UITextView. There are several options:

UIDataDetectorTypePhoneNumber

UIDataDetectorTypeLink

UIDataDetectorTypeAddress

UIDataDetectorTypeCalendarEvent

UIDataDetectorTypeNone

UIDataDetectorTypeAll

So, in your case, you'd probably want to do:

self.myTextView.dataDetectorTypes = UIDataDetectorTypeAll;
+16
source

Also note that the text view should not be edited when used NSDataDetectorTypes.

textView UITextView, :

textView.editable = NO;

, , ..

+4

You can use UIButton and change the title to a URL, email address or phone number.

Create a custom UIButton with the appropriate format so that it looks like a regular sentence (the edges and background of the button are the same color as the background of the view).

Format the text so that it looks blue (and not necessarily underlined), for example this , so that people know that it is a hyperlink.

0
source

All Articles