How can we highlight a text in textview like the imgage shown below,the user tap the select verse it hilight the verse in yellow color and a popup window apper for that verse for doing action.How to do this?
Thanks in advance.
How can we highlight a text in textview like the imgage shown below,the user
Share
It is only doable using CoreText, because it needs formatting attributes and
NSAttributedStringto display text with multiple font style and colors.You may be interested in my
OHAttributedLabelclass that is a subclass ofUILabelto renderNSAttributedString(obviously it uses CoreText for this).As setting the background color of a range of text is not directly possible/supported (no corresponding attribute in
NSAttributedString), you may need to draw the yellow rectangles (before drawing the text) yourself, but I’ve done this in my class too to manage highlighted links (seedrawActiveLinkHighlightForRect:method) so you may do a similar thing in your case.