Cocoa: display HTML from string

How can I display properly formatted text from an NSString that is just HTML. Html comes from API.

+2


a source to share


3 answers


You can create NSAttributedString from HTML . Then you will draw it as you would any other NSAttributedString.



+7


a source


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



Unfortunately, UIKit for iPhone OS doesn't include NSAttributedString until 4.0. The current recommendation from developer docs is to use UIWebView which sucks. An alternative could be the Three20 library which contains TTStyledText - it looks like it might work.

+1


a source


You can have a WebView and tell the WebView to mainFrame

load the HTML string .

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

0


a source







All Articles