views:

190

answers:

3

How can I display properly formatted text from an NSString, that just happens to be HTML. The html is coming from the stack overflow API.

+1  A: 

You can create a NSAttributedString from HTML. You then draw it as you would draw any other NSAttributedString.

zneak
Thanks! Works like a charm!
Matt S.
+1  A: 

If your tags are accurate and you are programming for OS X (or iPhone 4.0+), you can use NSAttributedString's – initWithHTML:documentAttributes:, and then draw that directly.

Unfortunately, the iPhone OS' UIKit does not contain NSAttributedString pre-4.0. The current recommendation from the developer docs is to use a UIWebView, which sucks. An alternative might be the Three20 library, which contains TTStyledText -- that looks like it might do the job.

Matt B.
A: 

You could have a WebView, and tell the WebView's mainFrame to load the HTML string.

If you meant to ask about Cocoa Touch, UIWebView has an equivalent method for you.

Peter Hosey