iOS7 UITextView 设置 NSLinkAttributeName 属性但无法点击 [英] iOS7 UITextView set NSLinkAttributeName attribute but can not click

查看:106
本文介绍了iOS7 UITextView 设置 NSLinkAttributeName 属性但无法点击的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

@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 > Utilities > Attributes Inspector 中设置以下内容.值得注意的是 UITextView 不能可编辑并启用链接.

Set the following in IB > Utilities > Attributes Inspector. Notably the UITextView cannot be editable and have links enabled.

你也可以用代码做同样的事情:

You can also do the same with code:

_textView.editable = NO;
_textView.dataDetectorTypes = UIDataDetectorTypeLink;

这篇关于iOS7 UITextView 设置 NSLinkAttributeName 属性但无法点击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆