How to decode UTF-8 string in a UITextView

What is the proper way to decode UTF-8 encoded html and present the text in a UITextView while keeping the HTML formatting?

I have the following title:
<p><strong>Pasta and Pizza</strong><br />

After UTF-8 decoding:
<p><strong>Pasta and Pizza</strong><br />

Finally I would like to present the text in a UITextView that respects the HTML tags:
Pasta and Pizza

I am pulling this content directly from a database, so I simply can’t pull the html page into a UIWebView. (I am not opposed to using a UIWebView. I simply don’t know how to implement that either.)

Hi @mmuldoon,
What you are after is called AttributedText (for UILabel and UITextView) if you don’t want to use a WebView.

You will have to strip the HTML tags and set the attributes for the text that is between the Bold text. I am not 100% sure from the top of my head, but there is a library that helps convert the HTML tags to Attributed Text, or from Markdown to attributedText which could be a good starting point.

cheers,

Jayant

1 Like