NSMutableAttributedString

NSMutableAttributedString

本文介绍了将点击事件添加到IOS NSMutableAttributedString的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个NSMutableAttributedString,例如鲍勃喜欢你的照片".

I have an NSMutableAttributedString such as "Bob liked your picture".

我想知道是否可以将两个不同的敲击事件添加到鲍勃"和图片"中.理想情况下,轻按鲍勃"将为新的视图控制器提供鲍勃的个人资料,轻按图片"将为新的视图控制器提供图片.我可以使用NSMutableAttributedString做到这一点吗?

I'm wondering if I can add two different tap events to "Bob" and "picture". Ideally, tapping "Bob" would present a new view controller with Bob's profile and tapping "picture" would present a new view controller with the picture. Can I do this with NSMutableAttributedString?

推荐答案

我处理它的方式是在UITextView中使用标准的NSString.然后利用UITextInput协议方法firstRectForRange:.然后,您可以轻松地在该区域中覆盖一个不可见的UIButton并处理您要采取的操作.

The way I would handle it is using a standard NSString in a UITextView. Then taking advantage of the UITextInput protocol method firstRectForRange:. Then you could easily overlay an invisible UIButton in that rect and handle the action you'd like to take.

这篇关于将点击事件添加到IOS NSMutableAttributedString的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-17 01:58