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

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
    关注
    评论

报告相同问题?

悬赏问题

  • ¥15 Qt下使用tcp获取数据的详细操作
  • ¥15 idea右下角设置编码是灰色的
  • ¥15 全志H618ROM新增分区
  • ¥15 在grasshopper里DrawViewportWires更改预览后,禁用电池仍然显示
  • ¥15 NAO机器人的录音程序保存问题
  • ¥15 C#读写EXCEL文件,不同编译
  • ¥15 MapReduce结果输出到HBase,一直连接不上MySQL
  • ¥15 扩散模型sd.webui使用时报错“Nonetype”
  • ¥15 stm32流水灯+呼吸灯+外部中断按键
  • ¥15 将二维数组,按照假设的规定,如0/1/0 == "4",把对应列位置写成一个字符并打印输出该字符