UIWebView、UITextView都有dataDetectorTypes属性,设置了该属性,系统可以自动检测电话、链接、地址、日历、邮箱。并且可以点击,当点击的时候可以在API中自定义事件,下面以UITextView为例.
- (void)viewDidLoad
{
[super viewDidLoad];
//UIWebView有dataDetectorTypes属性,UITextView也有dataDetectorTypes属性。
UITextView *textView=[[UITextView alloc] initWithFrame:self.view.bounds];
textView.delegate=self;
textView.font=[UIFont systemFontOfSize:14];
textView.editable=NO;
textView.text=[NSString stringWithFormat:@"%@%@%@%@\n\n\n%@",@"\n\n\n我的手机号是:13122718991 \n\n\n",@"我的博客是:www.baidu.com\n\n\n",@"上海市浦东新区盛夏路570号\n\n\n",[NSDate date],@"我的邮箱:2365178852@qq.com"];
textView.dataDetectorTypes=UIDataDetectorTypeAll;
[self.view addSubview:textView];
}
#pragma mark - UITextViewDelegate
-(BOOL)textView:(UITextView *)textView shouldInteractWithURL:(NSURL *)URL inRange:(NSRange)characterRange
{
NSLog(@"url=%@",URL);
return YES;
}