1

My app is reading JSON from server to show content for users. I have different values in this JSON: date, title, image, text content etc. Right now content is a plain text without markup that is placed into TextView. It is not so pretty and i can't use images in it.

What is the best way to send and show text with markup in iOS app?

moonvader
  • 19,761
  • 18
  • 67
  • 116

1 Answers1

0

You could send HTMLin the JSON and then convert it to a NSAttributesString with DTCoreText and set it to UITextViews's attributedText property. Unlike UIWebView UITextView with attributed content is synchronous so you can even get the content size before it's actually rendered. Remember to use DTUseiOS6Attributes option with DTHTMLAttributedStringBuilder to make the returned attributed string compatible with iOS6+ UITextView.

https://github.com/Cocoanetics/DTCoreText

Attributes strings can also have images:

iOS 7 TextKit - How to insert images inline with text?

Community
  • 1
  • 1
Tapani
  • 3,191
  • 1
  • 25
  • 41