开发者

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. ;-)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜