1

我有一个 TTTAttributed 标签,它可以自行检测链接,并且我有一个点击手势来执行一些操作。

问题是当我有一个点击手势时它无法打开链接它只能通过点击手势执行操作但我希望如果文本是链接类型然后我的点击手势将点击转发到链接TTTAttributed 标签的检测。

你的努力真的很感激。提前致谢。

4

2 回答 2

1
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.

于 2015-04-03T10:20:25.950 回答
1

检查[UITapGestureRecognizer state]点击手势识别器委托方法中的属性。在完成自定义点击手势处理后,根据该state值将事件传递给对象的以下触摸委托方法:TTTAttributedLabel

- touchesBegan:withEvent: - touchesMoved:withEvent: - touchesEnded:withEvent: - touchesCancelled:withEvent:

这应该负责执行TTTAttributedLabel类的默认行为。

于 2015-04-03T10:25:45.780 回答