How can I use multiple colors in a Label (Xcode/iPad)
For an application I'm building, I dynamically add text to a label. The first part of the lab开发者_JS百科el's text has to be black so I choose that color in Interface Builder. However the second part (the first part is a title second part a description) has to be darkgray.
Oh and note: 2 labels is not an option because of positioning.
There is no direct API to do that, however it's easy to subclass UIView class and use drawRect method to draw the strings by yourself using
CGContextSetRGBFillColor
to set the color and NSString
's drawInRect:
method to draw portions of text in specified rectangles
Or you could use a UIWebView to Format and color the text. ;-)
精彩评论