views:

2588

answers:

2

I have a UITextView object. The text in UIView has a phone number, mail link, a website link. I want to show them as links with following functionality.

When someone taps on URL - Safari should open the the website. When someone taps on email link - Mail should open up with my address in to field When someone taps on phone number - Phone application should call the number

Has anyone done this before or knows how to handle it?

Thanks, AJ

A: 

I'm curious, do you have control over the text shown? If so, you should probably just stick it in a UIWebView and throw some links in there to do it "the right way".

Ed Marty
There is a property (in SDK 3.0) dataDetectorTypes for UITextView. Which does the job of detecting links in text. But I am kinda unable to figure out how to use it. For versions prior to 3.0 I have used UIButton and make them look like links. On there touch event I am calling a method which has an NSURL object to the website. Using mailto:<email address here> would open the email in Mail app. Using Tel:<tel number here> would call the number.But thats the work around. Even after spendin 2 hours, still not able to figure out how to make UITextView handle these guys.
AJ
+2  A: 

If you are using OS3.0

you can do it like the following

textview.editable = NO;
textview.dataDetectorTypes = UIDataDetectorTypeAll;