ghf00123 2016-02-03 08:58 采纳率: 0%
浏览 3140

UITextView 添加链接NSLinkAttributeName,点击区域大于设定的区域

请问大家:使用UITextView添加链接 NSLinkAttributeName 时,有没有遇到过这种情况:点击区域实际是在设定范围内放大了(上方和左方为两个文字的宽或高,右边全部空白区域,如何解决? 谢谢!
图片说明
图片说明
图片说明

代码如下:
UITextView *tipsTextView = [[UITextView alloc] initWithFrame:CGRectMake(vPadding, 5, infoBgImgView.width - vPadding * 2, infoBgImgView.height - 5 * 2)];

tipsTextView.editable = NO;
tipsTextView.selectable = YES;
tipsTextView.delegate = self;
tipsTextView.dataDetectorTypes = UIDataDetectorTypeLink;



NSMutableAttributedString *muAttributedStr = [[NSMutableAttributedString alloc] initWithString:@"点击链接范围是设定区域及其上方的一行对应的区域,左方的两个字,以及右边的空白区域。再加文字,点击区域会发生变化,请至点链接区域"];

//添加链接

NSURL * url = [NSURL URLWithString:@"http://www.baidu.com"];

// tipsTextView.selectedTextRange = NSMakeRange(muAttributedStr.length - 5, 5);

NSRange selectRange = NSMakeRange(muAttributedStr.length - 5, 5);
[muAttributedStr addAttribute:NSLinkAttributeName value:url range:selectRange];

// [tipsTextView addObserver:self forKeyPath:@"contentSize"options:NSKeyValueObservingOptionNew context:nil];

tipsTextView.attributedText = muAttributedStr;
[infoBgImgView addSubview:tipsTextView];
  • 写回答

1条回答

  • devmiao 2016-02-03 14:31
    关注
    评论

报告相同问题?

悬赏问题

  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码