0

I have a UILabel with NSAttribtuedString and need to find all CGRects corresponding to a certain NSRange in the string. Is there any non-hacky way I can accomplish this?

I'm looking for this because I intend to overlay highlight views over the label like this: http://cdn.cultofmac.com/wp-content/uploads/2013/02/photo-1.jpg

I'm aware that UITextView is much more suitable for this as it implements UITextInput protocol (which has all the methods I need), but due to a bug in iOS I'm limited to UILabel.

I've looked for solution without success. This gist didn't work for me and I haven't found any UILabel subclass that would implement any such method that would help me.

Any suggestions? Pete.

Petr Mánek
  • 1,046
  • 1
  • 9
  • 24
  • You'll probably have more luck finding a workaround for the bug that getting this to work in UILabel. Does the bug still exist in ios7? – jrturton Sep 02 '13 at 05:40
  • I suppose you're right. Furthermore, the bug was fixed in iOS 7. It concerned the [line spacing when using custom font](http://stackoverflow.com/questions/12562506/nsparagraphstyle-line-spacing-ignored). My solution was to use multiline UILabel (which wasn't affected by it) instead of faulty UITextView. Guess I have to look for another way to get this working on iOS 6... – Petr Mánek Sep 02 '13 at 08:03

1 Answers1

0

UILabel doesn't have any methods to find rect from range. You can do it using UITextView (set UITextView editable property to NO) . UITextview implements the UITextInput protocol. you can get the rect from range using UITextInput protocol methods

hema
  • 199
  • 2