2

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
  • Make sure you don't parse SO's HTML with RegExes! Commented May 3, 2010 at 3:24

3 Answers 3

7

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

Sign up to request clarification or add additional context in comments.

Comments

1

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.

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.