在ios中创建以符号'@'Clickable开头的单词 [英] Create words starting with sign '@' Clickable in ios

查看:179
本文介绍了在ios中创建以符号'@'Clickable开头的单词的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个表视图,其中每一行包含各种信息,如姓名,图片,消息等。

I have a table view in which each row contains various information like name, picture, message etc.

此消息可能包含一些以开头的单词@''#'。我想让这些单词可点击,点击后我想打开另一个视图控制器而不是浏览器。

This message may contain some words starting with '@' or '#'. I want to make these words clickable and on click i want to open another view controller instead of browser.

我知道我们可以设置 UIDataDetector 在textview上键入链接,但仅适用于链接。

I know we can set UIDataDetector type on textview for links but that only works for links.

有没有办法告诉textview检测匹配某些正则表达式的文本然后点击该文本?

Is there any way so that I can tell textview to detect text matching some regular expression and then make that text clickable ?

编辑:
最后我能够做到这一点,对于那些仍在处理这个问题的人,我写了一篇博文:
http://www.uditagarwal.com/2013/10/make-different-words-in-uitextview。 html

推荐答案

答案: GLTapLabel

有一个名为 -drawTextInRect的方法在名为 GLTapLabel 的类中,其中包含一行代码:

There is a method named -drawTextInRect in class named GLTapLabel which contains one line of code :

BOOL hot = [word hasPrefix:@"#"] || [word hasPrefix:@"@"];

您只需在此处更改前缀值,即可获得所需的结果。

You just have to change the prefix values here and you will have your desired result.

有一个名为 -labledidSelectedHotWord 的委托方法。您可以在此处写下有关单击具有所需前缀的单词时要执行的操作的代码。在您的情况下,您可以使用此方法编写导航代码。

There is one delegate method named -labledidSelectedHotWord. You can write here the code about the action you want to perform when the word with desired prefix is clicked. In your case, you can write your navigation code in this method.

这是屏幕截图

这篇关于在ios中创建以符号'@'Clickable开头的单词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆