Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to a clickable url / email / phone number on UITextView

I am receiving a server response as a sting that can contain some url or email address or phone number ie same string can have all three of them or one number and couple of url. Nothing is fixed.

I am using UITextView to show this sting on device. Now what I want is these url/email/phone number show up as hyperlink and on clicking these hyperlink user should be able to see a webpage if its a url, draft and send an email if its email address or call the number when clicked on number hyper link

Can anyone suggest me a way to do this. Or suggest any other data view to be used which can make things easy

like image 642
Umang Avatar asked May 11 '11 12:05

Umang


2 Answers

Set the data detector types of your UITextView. There are a number of options:

UIDataDetectorTypePhoneNumber

UIDataDetectorTypeLink

UIDataDetectorTypeAddress

UIDataDetectorTypeCalendarEvent

UIDataDetectorTypeNone

UIDataDetectorTypeAll

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

self.myTextView.dataDetectorTypes = UIDataDetectorTypeAll;
like image 94
MarkPowell Avatar answered Sep 25 '22 01:09

MarkPowell


Also note that the textview should not be editable when you use NSDataDetectorTypes.

Let textView be an object for UITextView, then set:

textView.editable = NO;

then only it can detect the links, phone numbers, address etc.

like image 35
Ganesh S Bhat Avatar answered Sep 25 '22 01:09

Ganesh S Bhat