Why No NSAttributedString on the iPhone?

前端 未结 6 1451
春和景丽
春和景丽 2020-12-11 12:12

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

相关标签:
6条回答
  • 2020-12-11 12:21

    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

    0 讨论(0)
  • 2020-12-11 12:30

    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.

    0 讨论(0)
  • 2020-12-11 12:35

    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.

    0 讨论(0)
  • 2020-12-11 12:38

    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.

    0 讨论(0)
  • 2020-12-11 12:41

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

    0 讨论(0)
  • 2020-12-11 12:48

    NSAttributedString is now on the iPhone as of 4.0 Beta

    0 讨论(0)
提交回复
热议问题