How would I go about detecting links in TTTAttributedLabel?

时间:2021-07-10 23:12:17

I have a table view and in some of the cells there are links, I want to be allow the user to click on these links and view them in a webView (which I have already made). I don't want to use the row selection event because there may be more than one link in the cell. I came across TTTAttributedLabel and think it will be ideal. I don't need to add any style to the text in the cell, I only need to detect the links and capture the click event to open up my webview.

我有一个表视图,在一些单元格中有链接,我希望允许用户点击这些链接并在webView中查看它们(我已经制作)。我不想使用行选择事件,因为单元格中可能有多个链接。我遇到了TTTAttributedLabel,并认为这将是理想的。我不需要在单元格中为文本添加任何样式,我只需要检测链接并捕获click事件以打开我的webview。

Any help would be greatly appreciated.

任何帮助将不胜感激。

1 个解决方案

#1


6  

It looks like you can assign a TTTAttributedLabelDelegate to a TTTAttributedLabel that will get call backs for when a user selects different link types, but no opportunity for you to capture them and open your own web view (which I think is what you're trying to accomplish).

看起来您可以将TTTAttributedLabelDelegate分配给TTTAttributedLabel,当用户选择不同的链接类型时,它将获得回调,但是没有机会捕获它们并打开您自己的Web视图(我认为这是您正在尝试的完成)。

Instead, you might wanna check out OHAttributedLabel. It's similar in functionality, but when a user clicks on one of the links in the label, it calls -(BOOL)attributedLabel:(OHAttributedLabel*)attributedLabel shouldFollowLink:(NSTextCheckingResult*)linkInfo on it's OHAttributedLabelDelegate, which gives you the opportunity to handle the link tap yourself if you return NO.

相反,您可能想要查看OHAttributedLabel。它的功能类似,但是当用户点击标签中的一个链接时,它调用 - (BOOL)attributionLabel:(OHAttributedLabel *)attributionLabel shouldFollowLink:(NSTextCheckingResult *)linkInfo就可以了它的OHAttributedLabelDelegate,它让你有机会处理如果你返回NO,链接会点击你自己。

#1


6  

It looks like you can assign a TTTAttributedLabelDelegate to a TTTAttributedLabel that will get call backs for when a user selects different link types, but no opportunity for you to capture them and open your own web view (which I think is what you're trying to accomplish).

看起来您可以将TTTAttributedLabelDelegate分配给TTTAttributedLabel,当用户选择不同的链接类型时,它将获得回调,但是没有机会捕获它们并打开您自己的Web视图(我认为这是您正在尝试的完成)。

Instead, you might wanna check out OHAttributedLabel. It's similar in functionality, but when a user clicks on one of the links in the label, it calls -(BOOL)attributedLabel:(OHAttributedLabel*)attributedLabel shouldFollowLink:(NSTextCheckingResult*)linkInfo on it's OHAttributedLabelDelegate, which gives you the opportunity to handle the link tap yourself if you return NO.

相反,您可能想要查看OHAttributedLabel。它的功能类似,但是当用户点击标签中的一个链接时,它调用 - (BOOL)attributionLabel:(OHAttributedLabel *)attributionLabel shouldFollowLink:(NSTextCheckingResult *)linkInfo就可以了它的OHAttributedLabelDelegate,它让你有机会处理如果你返回NO,链接会点击你自己。