iOS - best practice to display formatted data - ios

i need to display some formatted data on one view. Some headlines, links and some bold and italic text. I wonder what would be the best way to achieve this.
I, right now, see two possibilities: Formatting in HTML and using UIWebView or placing some formatted UILabels.
Are there any other good ways in accomplishing this requirement?
I wonder what your learnings could be using either one of this or both ways.
BR, ~m

I like to use UIWebViews to display rich text. I include an HTML template with my app bundle, complete with CSS and then have placeholders in the to hold the various parts of an article.
<body>
<h1>%#</h1> // Header
<p>%#</p> // Article content
</body>
You can also use attributed labels, one being TTTAttributedLabel.
https://github.com/mattt/TTTAttributedLabel/

Check out DTCoreText - its much nicer (IMHO) to use that a UIWebView, and you can do really fancy things with it. Essentially it uses NSAttributedStrings as text representations, and you can either build those by hand or have this framework convert HTML to that. Lots of options to get callbacks when user taps images or links too.

Related

TextView to display formatted file in iOS

I want to use a UITextView to display the contents of a formatted file. I have various tutorials that I want to display.
Any suggestions will be appreciated.
To use rich text. It is NSAttributedString in Cocoa.
As Apple says:
NSAttributedString : A string that has associated attributes (such as
visual style, hyperlinks, or accessibility data) for portions of its
text.
Why not use UITextView if the file has multiple lines?
Assuming your users won't need to edit your various tutorials, another suggestion would be to load an HTML string (from a file or resource) into a UIWebView. This might make it easier for you to generate your content to be presented. It also gives you additional options for things like links, images, etc.

Rich text (with images) performance - UITextView vs UIWebview

I need to display rich text which may include a lot of images as is formatted as Markdown.
After some research I see that there are 2 most common approaches:
parse Markdown to HTML and display it within UIWebView
parse Markdown to NSAttributedString and feed it into UITextView which can use NSTextAttachments to display UIImages.
I'm wondering about possible issues with both approaches but mostly performance.
I'm aware that with UITextView I'm a bit limited as I can't use CSS to customise its look etc., but if you had some experience and there are a lot of issues with images alignment in UITextView that would be good to know too.
Additionally, as this may be relevant to others searching for possible functionality, I'm listing libs that I'm considering to use to handle Markdown:
AttributedMarkdown
Bypass
CocoaMarkdown
MarkdownTextView
With UIWebView you cannot get the frame size needed to display the content before it has been rendered (asynchronously). But with NSAttributedString you can get the bounds synchronously without first rendering the content. For this UIWebView is much slower.
I have used CSS with UITextView when converting HTML to NSAttributedString using DTCoreText. iOS has some own HTML to NSAttributedString conversion functions, but they are really, really slow.
Apple recommends the use of UITextView where possible
It’s recommended that you use a text view—and not a UIWebView object—to display both plain and rich text in your app.
Referene:
UITextView
Also to customize the looks you can use any RichText Libraries, like
SwiftRichString

UItextview vs UIWebView for showing long attributed text in the iOS

I want to show a variable text on my universal iOS application. I load the texts from SQLite DB as NSString and almost each line of the text has separated atributes like Color. So I need to use AttributedText. Also I want to support both ios 7 and ios 7 and also in future iOS 8.
I noticed that there is two general ways: 1- Using UITextView 2- Using UIWebView.
I am wondering what is the advantages and disadvantages of using above features and witch of the is better for showing long length and very attributed text. And also is there any other solution for showing this texts.
The biggest advantage of using UIWebView is that you can render an HTML content through it -- any HTML content, since it is backed by WebKit.
On the other hand, UIWebView will add a noticeable delay from the moment when you add it as a subview to the moment when it will have finished to render the HTML.
You could also give a look at alternatives like RTLabel and others that you may find on GitHub. RTLabel is built on top of Core Text and supports HTML-like markup.
EDIT:
Some of them are about 40000 characters. It should be about 1000 paragraphs and each paragraph 1 line.
My suggestion is to go for some kind of paging to let the user move comfortably through all that text (40k chars would be like 25-30 book pages). This would improve UX and it would also make feasible the implementation through a UITextView -- performance-wise.
If you do not want paging and want just one scrolling view, then UIWebView could be better for your case since it should also do some kind of optimisation regarding portions of the page that are not displayed.
Finally, as a side node, since you specify that your text has a fixed structure (1000 40-chars lines), another option which you could consider is using a UITableView for this, provided that you can display each paragraph in a single cell row. This would be the most efficient solution since you have short pieces of text and the table view to handle their allocation/deallocation based on which ones (usually a small subset) are displaying.

how can I add this formatted text for a help page in my ios app

I have this help page I want to add to my application, but I'm not sure of how to format it. At the moment it's just an image in a scrollview, but surely there's a better way?
Many apps use a WebView to display formatted text. You can then use CSS to style your content as needed.
You could use NSAttribuatedString + RTLabel to display it (or of cause the default cheat of a UIWebView).
To display RichText (NSAttribuatedString use one of these).
http://www.cocoacontrols.com/platforms/ios/controls/rtlabel
https://github.com/Cocoanetics/NSAttributedString-Additions-for-HTML
http://www.cocoanetics.com/2011/01/uiwebview-must-die/
https://github.com/AliSoftware/OHAttributedLabel
https://github.com/mattt/TTTAttributedLabel
Use webview to and with webservices so u can change it later so on

Is there an alternative to UIWebView for dynamically displaying formatted text?

Working on an app that needs to take a large amount of text, paginate it based on user selected font size, etc., and display it with styles. Getting UIWebView to paginate a document has proven extremely troublesome. I have seen a wrapper for Core Text that apparently, takes care of layout, but my understanding is that core text cannot be selected.
Looking to do something similar to the books available through the app "eReader", or the app made for the book "The Adderall Diaries". Anyone know how they accomplished this? I had assumed it was UIWebView.
Normally I'd say using UILabel with NSAttributedString, however since you also need to select text, things get a bit more complicated. Head over to the Apple Dev Forums and check out the changes in iOS 6 to attributed strings (it's under NDA).

Resources