解决方法
正如
this answer中所指出的,您可以设置UITextView的dataDetectorTypes属性:
textview.editable = NO; textview.dataDetectorTypes = UIDataDetectorTypeAll;
您还应该能够在Interface Builder中设置detectorTypes.
UIDataDetectorTypes
06001
单击UITextView中的电子邮件地址应该会自动打开Mail应用程序.
另外,如果您想从应用程序本身发送电子邮件,可以使用MFMailComposeViewController.
请注意,要显示MFMailComposeViewController,需要在设备上安装Mail应用程序,并将一个帐户链接到该应用程序,否则您的应用程序将崩溃.
所以你可以用[MFMailComposeViewController canSendMail]来检查这个:
// Check that a mail account is available if ([MFMailComposeViewController canSendMail]) { MFMailComposeViewController * emailController = [[MFMailComposeViewController alloc] init]; emailController.mailComposeDelegate = self; [emailController setSubject:subject]; [emailController setMessageBody:mailBody isHTML:YES]; [emailController setToRecipients:recipients]; [self presentViewController:emailController animated:YES completion:nil]; [emailController release]; } // Show error if no mail account is active else { UIAlertView * alertView = [[UIAlertView alloc] initWithTitle:@"Warning" message:@"You must have a mail account in order to send an email" delegate:nil cancelButtonTitle:NSLocalizedString(@"OK",@"OK") otherButtonTitles:nil]; [alertView show]; [alertView release]; }