时间:2021-02-24 09:35:20 | 栏目:iOS代码 | 点击:次
检测链接
大家都知道,UITextVview可以用以下方法自动检测text中的链接:
let label = UITextView() label.dataDetectorTypes = .link label.isEditable = false
如果我们使用的attributedString后,会发现如果添加Attachment后,会触发一个选择(编辑的GR),如果我们只想要链接的gr,不想要选择的gr,可以遍历并禁用它。方法如下:
传送门:http://stackoverflow.com/questions/18962742/uitextview-link-detection-in-ios-7
Objective-C
NSArray *textViewGestureRecognizers = self.captionTextView.gestureRecognizers; NSMutableArray *mutableArrayOfGestureRecognizers = [[NSMutableArray alloc] init]; for (UIGestureRecognizer *gestureRecognizer in textViewGestureRecognizers) { if (![gestureRecognizer isKindOfClass:[UILongPressGestureRecognizer class]]) { [mutableArrayOfGestureRecognizers addObject:gestureRecognizer]; } else { UILongPressGestureRecognizer *longPressGestureRecognizer = (UILongPressGestureRecognizer *)gestureRecognizer; if (longPressGestureRecognizer.minimumPressDuration < 0.3) { [mutableArrayOfGestureRecognizers addObject:gestureRecognizer]; } } } self.captionTextView.gestureRecognizers = mutableArrayOfGestureRecognizers;
总结
以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作能带来一定的帮助,如果有疑问大家可以留言交流。