简体   繁体   中英

Is there any way to get CGRects for NSRange in UILabel?

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM