user26218
user26218

Reputation: 65

Multi-colored UILabel text

Is is possible to create multi-colored text within a UILabel? I.e, if my text was:

"The quick brown fox"

have the q and b in blue with the rest of the text in black?

I get the feeling I'd have to use a UIWebView and render the text in HTML to accomplish this. Thoughts?

Upvotes: 2

Views: 3992

Answers (5)

Vicky
Vicky

Reputation: 1095

We can do it using CoreText Framework,You can study further more using this link CoreText Tutorial for iOS

Upvotes: 0

Pcasso
Pcasso

Reputation: 1

CoreText can be successfully used in many applications.

Upvotes: 0

Ken
Ken

Reputation: 31171

Another solution is to concatenate an array of UILabels each with their own individual settings (such as text colour). In your case the label would be broken into labels as [The ][q][uick ][b][rown fox].

Upvotes: 0

Daniel Dickison
Daniel Dickison

Reputation: 21882

You are correct that you need to use a UIWebView. Alternatively, you can draw the text yourself into a custom view, but that would probably be a lot more difficult to implement.

If you are going to draw it yourself, you'll want to use the drawing methods in NSString UIKit Additions along with the -[UIColor set] method etc.

Upvotes: 3

Dan Lorenc
Dan Lorenc

Reputation: 5394

Rendering the text using HTML in a UIWebView is the recommended method from apple.

Upvotes: 1

Related Questions