0

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 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.)

Martin Muldoon
  • 3,388
  • 4
  • 24
  • 55
  • Are you able to decode the string to **

    Pasta and Pizza
    ** ?

    – Nirav D Apr 04 '17 at 12:26
  • No @NiravD. I used this tool: http://www.cafewebmaster.com/online_tools/utf_decode just to verify that it was in a UTF-8 format. – Martin Muldoon Apr 04 '17 at 12:35
  • 1
    Related: [How do I decode HTML entities in swift?](http://stackoverflow.com/questions/25607247/how-do-i-decode-html-entities-in-swift) – Martin R Apr 04 '17 at 13:17
  • I was able to solve this using a combination of @MartinR 's StringExtensionHTML on GitHub for replacing HTML entities with HTML markup, and creating an attributed string as Nirav D suggested. – Martin Muldoon Apr 05 '17 at 14:26

0 Answers0