IOS how to make email address in clickable shortcut

I believe that this question has been asked and answered before, but I could not find it. I see an answer pointing to Fancy Label and Three20, but they are not exactly what I want, or maybe I missed some points.

Basically, I want to get user reviews of applications, so I’ll write on a big label, for example, blah blah, write me at xxxxxx@gmail.com and again. I want the email address to be clickable and open the email composer so that users can edit and send.

It's all I need. How to get it? Thanks.

+8
ios email
source share
4 answers

You can use UITextView as follows:

UITextView *myView = [[UITextView alloc] initWithFrame: CGRectMake(0, 0, 300, 50)]; myView.text = @"this is http://google.com link"; myView.editable = NO; myView.dataDetectorTypes = UIDataDetectorTypeLink; //myView.message.dataDetectorTypes = UIDataDetectorTypePhoneNumber|UIDataDetectorTypeLink; for multiple data detection [self.view addSubview:myView]; [myView release]; 

To select more than one data discovery:

enter image description here

+7
source share

It’s pretty simple

create shortcut in .h file

 @interface ContactUsViewController : UIViewController<MFMailComposeViewControllerDelegate> @property (strong, nonatomic) IBOutlet UILabel *mail1Lbl; 

and put this code in a .m file

 - (void)viewDidLoad { [super viewDidLoad]; UITapGestureRecognizer* mail1LblGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(mail1LblTapped:)]; // if labelView is not set userInteractionEnabled, you must do so [mail1Lbl setText:@"xxxxxx@gmail.com"]; [mail1Lbl setUserInteractionEnabled:YES]; [mail1Lbl addGestureRecognizer:mail1LblGesture]; } - (void)mail1LblTapped:(id)sender { if ([MFMailComposeViewController canSendMail]) { MFMailComposeViewController *mailer = [[MFMailComposeViewController alloc] init]; mailer.mailComposeDelegate = self; [mailer setSubject:@""]; NSArray *toRecipients = [NSArray arrayWithObjects:@"xxxxxx@gmail.com", nil]; [mailer setToRecipients:toRecipients]; NSString *emailBody = @""; [mailer setMessageBody:emailBody isHTML:NO]; mailer.navigationBar.barStyle = UIBarStyleBlackOpaque; [self presentModalViewController:mailer animated:YES]; } else { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Failure" message:@"Your device doesn't support the composer sheet" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]; [alert show]; } } - (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error { switch (result) { case MFMailComposeResultCancelled: NSLog(@"Mail cancelled: you cancelled the operation and no email message was queued."); break; case MFMailComposeResultSaved: NSLog(@"Mail saved: you saved the email message in the drafts folder."); break; case MFMailComposeResultSent: NSLog(@"Mail send: the email message is queued in the outbox. It is ready to send."); break; case MFMailComposeResultFailed: NSLog(@"Mail failed: the email message was not saved or queued, possibly due to an error."); break; default: NSLog(@"Mail not sent."); break; } // Remove the mail view [self dismissModalViewControllerAnimated:YES]; } 
+2
source share

Web browsing using html / mailto: anchor should work fine for this ... you may need to style it by default for iOS, but yes.

+1
source share

You can use NSAttributedString for this. Using this type of string will save a lot of time. But before that you must know the exact position of the text. Knowing the position and length, you can easily customize this line. See this link for a sample project download. NSAttributed string . But if you are using ios 6, then you do not need to use this sample code. You can directly use NSAttributedString. Since in ios6 UILabel supports this type of string.

 lbl.aatributText = @"Your NSAttributed string". 

Edit: Here are some links you can follow: 1. Create a link to the "link" channel in NSAttributedString UILabel? 2. Objective-C UILabel as HyperLink 3. how to make a specific word tangible for its meaning in the text?

+1
source share

All Articles