Add gesture recognizer gestures to a specific word in UITextView

I have a UITextView with some text. This text is an attribute string ( NSAttributedString ). There are certain parts of the text that I set to bold, and I want to add TapGestureRecogniser only to these specific words.

So far, I have used the textViewDidChangeSelection method of the textViewDidChangeSelection delegate. But this causes problems in other parts of the project.

Is there a more direct approach to this?

+1
ios uitextview uitapgesturerecognizer
Jul 10 '13 at 11:14
source share
1 answer

You can add a GestureRecognizer to the view, and not to some words. This is a rather difficult task, there is no simple solution.

I can think in some approaches, for example:

  • Place a transparent look on top of bold words to get a Tap.
  • Detecting Tap throughout the UITextView, and then calculating based on the position of the touch and the position of the bold words if it hits.

Both options require a lot of code and many extreme cases when it can fail.

As I said, this is a very difficult situation, you can continue to use textViewDidChangeSelection and fix problems, we can help you.

+2
Jul 10 '13 at 11:20
source share



All Articles