How do you use NSAttributedString?

Multiple colours in an NSString or NSMutableStrings are not possible. So I’ve heard a little about the NSAttributedString which was introduced with the iPad SDK 3.2 (or around 3.2) and is available on the iPhone as of iPhone SDK 4.0 beta.

I would like to have a string that has three colours.

The reason I don’t use 3 separate NSStrings, is because the length of each of the three NSAttributedString substrings changes often and so I would prefer, not to use any calculations to re-position 3 separate NSString objects.

If it’s possible using NSAttributedString how do I make the following – (if not possible with NSAttributed string how would you do it):

alt text

Edit:
Remember, @"first", @"second" and @"third" will be replaced by other strings at any time. So using hardcoded NSRange values won’t work.

15 Answers
15

Leave a Comment