我有一个 TTTAttributed 标签,它可以自行检测链接,并且我有一个点击手势来执行一些操作。
问题是当我有一个点击手势时它无法打开链接它只能通过点击手势执行操作但我希望如果文本是链接类型然后我的点击手势将点击转发到链接TTTAttributed 标签的检测。
你的努力真的很感激。提前致谢。
我有一个 TTTAttributed 标签,它可以自行检测链接,并且我有一个点击手势来执行一些操作。
问题是当我有一个点击手势时它无法打开链接它只能通过点击手势执行操作但我希望如果文本是链接类型然后我的点击手势将点击转发到链接TTTAttributed 标签的检测。
你的努力真的很感激。提前致谢。
label.enabledTextCheckingTypes = NSTextCheckingTypeLink; // Automatically detect links when the label text is subsequently changed
label.delegate = self; // Delegate methods are called when the user taps on a link (see `TTTAttributedLabelDelegate` protocol)
label.text = @"Google it! (https://www.google.co.in/)"; // Repository URL will be automatically detected and linked
NSRange range = [label.text rangeOfString:@"Google"];
[label addLinkToURL:[NSURL URLWithString:@"http://google.com/"] withRange:range]; // Embedding a custom link in a substring
Set the delegate of the TTTAttributed label and when the user will tap on the label its delegate method will get invoked.
(void)attributedLabel:(TTTAttributedLabel *)label didSelectLinkWithURL:(NSURL *)url
Handle your event in this delegate method.
检查[UITapGestureRecognizer state]
点击手势识别器委托方法中的属性。在完成自定义点击手势处理后,根据该state
值将事件传递给对象的以下触摸委托方法:TTTAttributedLabel
- touchesBegan:withEvent:
- touchesMoved:withEvent:
- touchesEnded:withEvent:
- touchesCancelled:withEvent:
这应该负责执行TTTAttributedLabel
类的默认行为。