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
If you are using OS3.0
you can do it like the following
Swift 3.0 +
As of swift 3.0, use the following code if you want to do it programmatically.
Or if you have a storyboard
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".
A note on detecting email addresses: The Mail app must be installed (it's not on the iOS Simulator) for email links to open a message compose screen.
Though the Question is super Old. Still if anyone faces the same issue,
Also it can be used as a UILabel. Though Below solution will do the job : [There isn't a need for any library..]
So I've used MFMailcomposer() and UITexView [ Code is in Swift 3.0 - Xcode 8.3.2 ]
A 100% Crash Proof and Working Code Handles all the corner cases. =D
Step 1.
Step 2. Add the delegate
class ViewController: UITextViewDelegate, MFMailComposeViewControllerDelegate{
Step 3. Add the textView IBOutlet From StoryBoard
Step 4. Call the below method in your viewDidload()
Step 5. Implement delegate methods for TextView
Step 6. Write the helper Methods to open MailComposer and Call App
Step 7. Write MFMailComposer's Delegate Method
Here is the swift file for the above code : textViewWithEmailAndPhone.swift
Step 1. Create a subclass of UITextview and override the canBecomeFirstResponder function
KDTextView.h Code:
KDTextView.m Code:
Step 2. Create the Textview using subclass KDTextView
Step 3: Implement the delegate method