views:

2565

answers:

6

Hey guys,

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?

+3  A: 

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.

Ben Gottlieb
I was afraid of that. Thanks for the advice.
Jasarien
+1  A: 

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.

Kendall Helmstetter Gelner
Really? WebViews? Don't they take up a lot of memory just to show a label?*confused*.
Jasarien
Not really that much memory when you are using a shared rendering engine... remember this is WebKit, and not really a full browser or even Javascript interpreter.
Kendall Helmstetter Gelner
@Kendall: uh? WebKit (UIWebView) *is* a full browser with JS interpreter.
porneL
+4  A: 

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

Lounges
+4  A: 

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.

MrMage
+4  A: 

NSAttributedString is now on the iPhone as of 4.0 Beta

coneybeare
Yes, I know, great news :D
Jasarien
As well as Core Text, which enables lots of cool stuff.
Paul Shapiro
A: 

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

Harkonian
That is true, but 3.2 is only supported for iPad. iPhone apps still have to wait until 4.0.
Jasarien
Ah, good catch.
Harkonian