Reputation: 161
I would like to highlight or change the color of certain words within text, like when you search for a term, you get the highlighted words within search results. I know I can't do this with NSStrings, but How will I able accomplish this? I would like to display text in UITextView, but can do other options if I need to.
Thanks
Upvotes: 1
Views: 1674
Reputation: 3738
I prefer using EgoTextView, you can change color for range of texts. Please check the code here.
Upvotes: 0
Reputation: 535306
In iOS 6 you can do it, because iOS 6 now allows UITextView (as well as UILabel, UIButton etc.) to display styled text (NSAttributedString). You color the word with NSForegroundColorAttributeName
and color its background with NSBackgroundColorAttributeName
and presto, there's your highlight. There are several very good WWDC 2012 videos on this topic.
Upvotes: 2
Reputation: 1931
The only way I can think right now will be using an UIWebView and using CSS and javascript to highlight words.
You can check this stack overflow answer fo an example of how to highlight text with jQuery and CSS.
Also you can check this example
Upvotes: 0