苹果提供的控件中具有自动识别URL、电话、邮箱等功能,并且点击可跳转的似乎只有UITextView,那这里先介绍UITextView的自动识别URL。
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor whiteColor];
UITextView *textView = [[UITextView alloc] initWithFrame:CGRectMake(15, 100, self.view.frame.size.width-30, 100)];
//系统会为其默认设置距UITextView上、下边缘各8的页边距
textView.textContainerInset = UIEdgeInsetsMake(0, 0, 0, 0);
//textContainer中的文段的上、下、左、右又会被填充5的空白
textView.textContainer.lineFragmentPadding = 0;
textView.backgroundColor = [UIColor greenColor];
textView.font = [UIFont systemFontOfSize:14];
textView.textColor = [UIColor orangeColor];
textView.text = @"换地方第www.baidu.com";
//禁止编辑
textView.editable = NO;
//设置需要识别的类型,这设置的是全部
textView.dataDetectorTypes = UIDataDetectorTypeAll;
[self.view addSubview:textView];
}
展示图如下:
网友评论