0

What would be the best way to display long passage with rich text style(multiple font styles, color, image).

Attached screen is similar to the kind of content I need to display.

enter image description here

Santosh Singh
  • 765
  • 11
  • 27
  • What's wrong with UITextView? It gives you the full Text Kit engine; that's as fast, powerful, and full-featured as it gets on Mac or iOS. – matt Feb 03 '18 at 22:59
  • 1
    How can we show the image, text with multiple fonts and styles? We could use attributedString for this but content size is too long(30 pages) – Santosh Singh Feb 03 '18 at 23:02
  • Honestly at this point in the app I would just **leave and go to a web page**. ie, an internet URL. Every single app these days, when you come to (for example) the legal terms and conditions. It just cuts away to a normal URL in Safari. There's no other real solution. – Fattie Feb 03 '18 at 23:09
  • 1
    @Fattie, I do have other solution like use DTCoreText(https://github.com/Cocoanetics/DTCoreText) kind of thing but for this, I have to restructure content again into HTML and display it, it will not lag in performance as well. I fear to create HTML for all content, not sure if it is the best solution. – Santosh Singh Feb 03 '18 at 23:14
  • 1
    "We could use attributedString for this but content size is too long(30 pages)" I don't know why you say it's too long. You could lay it all out with PDF Kit if you want to paginate. – matt Feb 03 '18 at 23:35
  • 1
    @matt PDF is another option but again need to create formatted PDF. – Santosh Singh Feb 04 '18 at 07:41

1 Answers1

2

The by far easiest approach is to convert your rich text to HTML and use a UIWebView to display it. The web view will take care of so many things:

  • formatting
  • scrolling
  • loading fonts asynchronously
  • loading images asynchronously
Ringo Store
  • 606
  • 3
  • 10
  • 1
    Good luck in finding an alternative that is sufficiently powerful and faster. – Ringo Store Feb 03 '18 at 22:16
  • hi @SantoshSingh - this is the correct answer. You "shouldn't be" displaying crap like this in an app. if you have to do so - use a UIWebView! – Fattie Feb 03 '18 at 23:01
  • 1
    Agreed, but as per my customer requirement, they have to display the long list of pages. There are many apps which use the long passage to display. – Santosh Singh Feb 03 '18 at 23:06
  • **Those apps use UIWebView.** Also just tell your client "you simply go to a web page for that". Note too that means the web page can be maintained over time. – Fattie Feb 03 '18 at 23:10
  • @Fattie Agreed, but they have special requirements, I see few apps good in rich styling. For example, Mimo(https://itunes.apple.com/us/app/mimo-learn-to-code-on-the-go/id1133960732?mt=8) how they are doing this. – Santosh Singh Feb 03 '18 at 23:26
  • they use UIWebView. – Fattie Feb 04 '18 at 02:24
  • 1
    @Fattie Maybe UIWebView or they would have used NSAtttribuedString from HTML content for rendering. Isn't? NSAttributedString(data: self, options: [.documentType: NSAttributedString.DocumentType.html, .characterEncoding: String.Encoding.utf8.rawValue], documentAttributes: nil) – Santosh Singh Feb 04 '18 at 07:27
  • 1
    actually @SantoshSingh you may want to review this https://stackoverflow.com/questions/43723345 very complicayed and annoying issue! just FYI – Fattie Feb 04 '18 at 14:40
  • @SantoshSingh: DTCoreText is a nice thing for this. –  Feb 05 '18 at 08:02