Suggestions for Displaying Several RichText Paragraphs iOS5 - ios5

I am building an iPad app that needs to display certain RichText parapraphs
Title1 (bold and big font)
Description1 (rich text may contain images)
Title2 (bold and big font)
Description2 (rich text may contain images)
Title3 (bold and big font)
Description3 (rich text may contain images)
and so on.....
What is the best way to display this information in a ViewController?
I have looked at UIWebView and from the looks of it, it needs either a URL or a HTML String that it can load. Whereas, in my scenario, I have multiple HTML strings that need to go in different places on the screen.
Any ideas what is the best way to deal with this? Can I instead use a UITextView?
Thanks in advance.

Related

Formatting text in a list in app inventor 2

I have a list that I want to display some text as bold and other parts not bold. First of all I have been accomplishing this when not inside of a list by just making a bunch of labels and then manually going through the text adding \n and spaces for formatting, which takes forever. If there is an easier way of doing that I would love to know. Anyway my question is how can I add formatted text to a list.
So instead of those individual text elements I want to add multiple formatted text elements in place of one.
how can I add formatted text to a list
sorry, that's unfortunately not possible with App Inventor
you can take a look at this App Inventor Classic example, which uses some HTML to do the formatting

Best way to display text with HTML tags in iOS application?

Currently I am working on iOS client for web-chat. Thus chat messages have HTML tags (bold, italic, underlined, font color, images (smiles), etc.). For example:
<b>bold</b> <i>italic</i> <!--smile:bird--><img style="vertical-align: middle;border: none;" alt="bird" src="http://www.site.com/engine/data/emo_chat/bird.gif" /><!--/smile--> ordinaty text
For the moment I have 2 ideas how to display messages:
Add UIWebView to tables cell. But I think that it's not an option, because we will have a lot of messages and a lot of WebViews.
Add UITextView to tables cell, parse HTML tags and make necessary changes to attributed string. But UITextView doesn't support images (if I am right).
Is there any other (better) way to display such data (styled text + images)?
Using a webview per-cell is not going to work as you suspect. Webviews take a noticeable time to render which means you will likely end up with old webview content being momentarily displayed in reused cells until the new content renders. Webview is also a pretty heavy-weight UI element and you will encounter performance issues with having many of them on the screen updating at once.
You will want to parse the HTML text you are given into an attributed string using a library like DTCoreText. From here, if you can target iOS 6 or later you can set the attributedText property on a standard UILabel. If you need to target earlier iOS versions you can again use DTCoreText, specifically the DTAttributedLabel or DTAttributedTextCell components.
The parsing and NSAttributedString rendering can all be done manually using an XML parser and CoreText, but DTCoreText will make your life much easier.
Update: You mentioned in a comment that you want support for <img/>. DTCoreText does have some basic image support, but this is a really hard problem if you are rendering text with CoreText because you have to make text flow around the image correctly, and reserve some space in the core text renderer to put your image into. If there is just a single image for each cell, I would suggest you manually extract the image path/url and lay it out with a UIImageView alongside your text.
You can get idea from RTLabel stuff. It is doing same thing which you want.
You can also convert HTML to NSAttributedString with native iOS classes. Look the following post
https://stackoverflow.com/a/18886718/1760527

Custom Font in Text View/Interface Builder

I hope this is a really simple question, but it's stumped me. Basically, I have a huge amount of text that I'm using the text view for. For the most part, it's just the system font. However, I would like to format "headers" every few paragraphs in the large chunk of text with a custom font (that I've added to my project) and background color. How do I target small pieces of text within the text view?
If it were just a small piece of text, I would just add a label and do it with code, but since this a huge piece of text, what's the best way to do it?
Thanks!
If you load a large amount of static text with formatting, I suggest you save it as a html file and load it into UIWebView.

Adding rich text in localizable.strings

Is it possible to add some sort of styling to my localizable.strings file.
For example
"HELLO_WORLD" = "Hello \bold WORLD \bold";
No, it is not possible. Localized strings can be used in many places in your code and UI, only some of which may support display of rich text. For example, a UILabel has a text property that you can set from a localized string but it has no capability of showing rich text.
You will need to choose some way of displaying rich text in your UI then decide how you are going to encode that text in a localized string. You may end up having to parse the localized string and do custom text drawing depending on where and how you want to display the text.

How to upload contents of a file to a UITextView?

I have about twenty UITextViews and corresponding .txt files. What I want is to make each UITextView take the contents of the corresponding file and display it.
Moreover, the text is formatted and it contains some formulas (copy/pasted from Grapher). I've heard about displaying formatted text in UIWebView, but I haven't found a clear explanation anywhere.
Thanks in advance!
Text files normally don't contain formatted text.
If by "formatted" you mean "html" then yes, you will want to use UIWebView. Basically you will convert the text to an HTML document, and then use the web view to display that document. There are several example projects available from Apple that show you how to use UIWebView.
Displaying formula in a UITextView will be difficult as the character rules for formula are completely different from language text. You could generate HTML to display it that but that is difficult as well.
I think your best bet would be to draw the formula to an image and then display the image. That is the traditional way to handle the display of formula.