Formatting text in UILabel in different ways

I would like different words in UILabel to be different colors. Does this mean that every word should be a different UILabel? I suppose yes, although it would be nice to just put color codes in a shortcut, as you know? I guess I'm a little messed up with text markup in HTML.

+4
source share
3 answers

On iOS, there is no proper UIRichTextView . This is high on my wish list for iOS 6 (and there is some reason to believe that we can get it then due to the release of pages).

Your options should use multiple UILabel , NSString UIKit Additions , Core Text, UIWebView or one of several third-party frameworks such as

  • NSAttributedString-HTML-Add-ons
  • CoreTextWrapper
  • OHAttributedLabel
  • Omniui

All current solutions have different problems. The most common problem is that it is difficult to use the select and copy functions to work with rich text if you are not using a web view. Web views are incredibly annoying because they are asynchronous and you have to do a lot of your interactions in JavaScript.

I want a better answer.

(Mandatory shilling: this topic is covered in detail in Chapter 18 of iOS 5 Programming Pushing the Limits .)

+5
source

UILabel does not support segmented formatting (everything can have only one format).

Check out the OHAttributedLabel , which does what you want.

+2
source

As far as I know, you need to have separate labels for each color word. Depending on what you are trying to do, you can use myLabel.textColor to change colors periodically or events, etc.

0
source

All Articles