_textView = [[UITextView alloc] initWithFrame:CGRectMake(100, _myView.bottom, 190, 100)];
_textView.backgroundColor = [UIColor yellowColor];
_textView.text = @"你好吗\n我们是谁术有专攻 桂花村械15801270154 gaoyuqiang30@126.com http://www.baidu.com";
NSDictionary *linkAttributes = @{NSForegroundColorAttributeName: [UIColor blueColor],
NSUnderlineStyleAttributeName: @(NSUnderlineStyleSingle)};
_textView.linkTextAttributes = linkAttributes;
_textView.delegate = self;
_textView.editable = NO;
_textView.dataDetectorTypes = UIDataDetectorTypeLink | UIDataDetectorTypePhoneNumber | UIDataDetectorTypeAddress;
[self.view addSubview:_textView];
[self testTuple];
}
- (BOOL)textView:(UITextView *)textView shouldInteractWithURL:(NSURL *)URL inRange:(NSRange)characterRange {
if ([URL.scheme isEqualToString:@"tel"]) {
NSLog(@"phone---");
return NO;
} else if ([URL.scheme isEqualToString:@"mailto"]) {
NSLog(@"mail");
return NO;
} else {
NSLog(@"url");
return NO;
}
return YES;
}
给textView添加url、电话号码、邮箱点击效果
最新推荐文章于 2022-10-21 10:29:49 发布
