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
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;
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With