@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;
}
有什么不对?
在 IB > 实用程序 > 属性检查器中设置以下内容。特别是 UITextViewcannot可编辑并启用链接。
您也可以使用代码执行相同的操作:
_textView.editable = NO;
_textView.dataDetectorTypes = UIDataDetectorTypeLink;
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)