开发者

Cocoa: Display HTML from string

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.


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


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜