PDA

View Full Version : How to highlight PART of a text in UILabel?




HARDWARRIOR
Apr 11, 2009, 09:17 AM
Hi
To display search results in my app I want a PART of text in UILabel to be drawn in color that differs from rest of text. How can I do that? Is it possible at all?
Why I'm using UILabel? I cant use UITextView because of it's well known bug: it does not display text if it was assigned to it out of display area. I need to render text in tableView cells. So it's common for some of them to be out of screen. UIWebView? Well... This one might work... if I'll feed it with on-the-fly generated html. But looks like very complicated. So is there a simple way?



ghayenga
Apr 11, 2009, 10:58 AM
Hi
To display search results in my app I want a PART of text in UILabel to be drawn in color that differs from rest of text. How can I do that? Is it possible at all?
Why I'm using UILabel? I cant use UITextView because of it's well known bug: it does not display text if it was assigned to it out of display area. I need to render text in tableView cells. So it's common for some of them to be out of screen. UIWebView? Well... This one might work... if I'll feed it with on-the-fly generated html. But looks like very complicated. So is there a simple way?

Sadly, If you have more than 2 or 3 tableViewCells putting a UIWebView on them and rendering HTML on the fly is just too slow. I've tried it, and when you scroll the table everything gets all messed up.

You'll have to draw the text into the label's drawing rectangle yourself, using the Drawstring methods.