Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Kaisser

macrumors newbie
Original poster
May 15, 2012
1
0
Hello all.

I have a problem.
I need to change the color of a word in a text. One word of a text in a color and the whole text, excep the word, in another color.

is it possible?

Thanks!
 
Not with any of the standard text UI elements on the iPhone.

Personally, I use UIWebViews to get rich formatted text in iOS apps. Just have them load a local html file.
 
Perhaps. But there is the NSAttributedString class that can be leveraged. Using it is rather tricky (just read through the Class Reference), so I suggest using a third-party library class to make things easier. I've used TTTAttributedLabel by Matt Thompson.

Ah. I've always been reluctant to use third party libraries. I feel like it's cheating somehow to use those even though I'd use the same library if it came from Apple.
 
Ah. I've always been reluctant to use third party libraries. I feel like it's cheating somehow to use those even though I'd use the same library if it came from Apple.

I don't feel it's cheating. I feel it's not "reinventing the wheel". I do, however, make sure to look through the source extensively to get a very good grasp of how it works. One should rarely incorporate third-party code without a good understanding of what it does.
 
I also do this by using some HTML inside a small textfield-sized UIWebView. Only a few extra lines of code required, and one can write a small custom class to do even that little bit.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.