Transform an NSAttributedString to plain text
If I understand you correctly you have an
data, containing an encoded
NSAttributedString. To reverse the process:
NSAttributedString *nas = [[NSAttributedString alloc] initWithData:data options:nil documentAttributes:NULL error:NULL];
and to get the plain text without attributes you then do:
NSString *str = [nas string];
How do you use NSAttributedString?
Multiple colours in an
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
If it’s possible using
When building attributed strings, I prefer to use the mutable subclass, just to keep things cleaner.
That being said, here’s how you create a tri-color attributed string:
typed in a browser. caveat implementor
Obviously you’re not going to hard-code in the ranges like this. Perhaps instead you could do something like: