@interface ViewController ()<UITextViewDelegate>
- (void)viewDidLoad
{
[super viewDidLoad];
NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:@"www.google.com"];
NSDictionary *linkDic = @{ NSLinkAttributeName : [NSURL URLWithString:@"http://www.google.com"] };
[str setAttributes:linkDic range:[[str string] rangeOfString:@"www.google.com"]];
_textView.attributedText = str;
}
- (BOOL)textView:(UITextView *)textView shouldInteractWithURL:(NSURL *)URL inRange:(NSRange)characterRange
{
NSLog(@"=============%@",URL);
return YES;
}
有什么问题吗?