Question

Does anyone know what made Apple leave out NSAttributedString when turning AppKit into UIKit?

The reason I ask is that I would really like to use it in my iPhone app, and there appears to be no replacement or alternative than doing it myself...

It is possible to have mixed font attributes on a string - it's just a hell of a lot of work to to achieve something similar that was possible with a few lines of code with NSAttributedString.

Also, doing all this extra drawing code myself makes my table view cells really heavy, and really hurts performance.

Anyone got any ideas? Any genius's working on an opensource alternative to NSAttributedString?

Was it helpful?

Solution

NSAttributedString is now on the iPhone as of 4.0 Beta

OTHER TIPS

The current from the documentation recommended way to do it is to use a UIWebView.

I don't know if this is still relevant for you, but Joe Hewitt has published his three20 library in the meantime, which contains TTStyledText and TTStyledTextLabel to fit your needs.

I'm afraid you're going to have to roll your own. If you're getting bogged down when doing table drawing, I'd probably switch to raw Quartz calls; try and dump all your drawing into a single view, and do all your complex string drawing within it. NSAttributedString is handy, but I don't think it's using all that much special AppKit-mojo to get much better performance than straight string drawing calls.

The answer above indicates that NSAttributedString is available on OS 4.0 and above, but per the documentation it's available on 3.2:

NSAttributedString Class Reference
Inherits from NSObject
Conforms to NSCoding, NSCopying, NSMutableCopying, NSObject (NSObject)
Framework /System/Library/Frameworks/Foundation.framework
Availability Available in iPhone OS 3.2 and later.
Companion guide Attributed String Programming Guide
Declared in NSAttributedString.h

Another approach would be to use a UIWebView with HTML. Or, if you are daring you can make use of the undocumented setHTML method on UITextView to set small snippets of formatted text...

To me this seems more like the future of where supporting formatted text will go, some way to leverage Webkit in outputting formatted strings.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top