Display Rich Text Content as UIWebView or UILabel+CoreText - iphone

I'd like to display rich text content in my app. I want user to create simple WYSIWYG input with support of bold, italics, shadow, outline, image HTML-like tags. I am puzzled if I should go with UIWebView or custom written UILabel/UIView which can have CoreText framework added to support all those above stated properties. I see there are libraries which are using both approaches.
Does anyone have an experience dealing with these approaches who can suggest cons and pros? Thanks

The web view approach has quite an overhead and likely a delay to display the rendered text. I would recommend using DTCoreText.

Related

How to select text in DTAttributedTextView?

I'm using DTCoreText DTAttributedTextView in my app to highlight the urls in my text. My other criteria is to be able to select by tapping and holding similar to UITextView. However, DTAttributedTextView doesn't seem to to use a UITextView as a placeholder. Anybody has an idea how I can achieve this?
Thanks
That's a feature that's only available via the paid version of DTCoreText.
from the github page
This is useful for drawing simple rich text like any HTML document without having to use a UIWebView. For text selection and highlighting (as you might need for an Editor or Reader) there is the commercial DTRichTextEditor component which can be purchased in the Cocoanetics Parts Store.

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

iphone: How do I make one scrollable field which contains multiple fonts and images?

I need to create one scrollable field which contains multiple fonts and images. Is that possible? I was thinking of using UITextView for this field, but I doubt that it can do what I need it to do.
If this field is not in a UITableView, then the easiest solution would be to organize your content in a html document then present it in a UIWebView which will work on both iOS5 and iOS6. Fonts can be handled through webfonts and styled via. css. Otherwise, you'll have some work to do.
You can learn about webfonts here:
https://developers.google.com/webfonts/docs/getting_started
For rich text in a UITextField ...
Well, there's good news and bad news. The good news is that it's pretty easy to do on iOS6. It's just a matter of creating an NSAttributedString and passing the string into a UITextView. The text should be formatted as you describe in an NSAttrbutedString.
If you haven't used an NSAttributedString, you can start learning about them over here:
How do you use NSAttributedString?
If you have an Apple developer account, check out the WWDC 2012 video: Introduction to Attributed Strings for iOS
https://developer.apple.com/videos/wwdc/2012/
Now the bad news ... this is not included in iOS5. So you have to a) build your own custom view using something like CoreText to render the text, b) punt and use a UIWebView (a terrible idea in a table view), or c) you can check out some of other home grown solutions such as these:
https://github.com/AliSoftware/OHAttributedLabel
https://github.com/enormego/EGOTextView#readme
There are more but you'll have to kick around google to find them.
As for images, it's just a matter of organizing the imageviews alongside the text views. Make sure to put all the content in a UIScrollView and you should be on your way.
Good luck!

iPhone and iPad Rich Text Editor

I need to create a rich text editor (for text alignment, fonts, text and background colours, bold, italics, underlining etc) for an iPhone and iPad app. How should I accomplish. I have heard of storing the data as HTML and rendering it in a UIWebView, but how can I allow the user to edit the data without having to interact with the HTML source?
Go into the style part of Three20 UI. It may be what you need for. I don't know if it is a overkill for a starter, but you may try

Should I use UIWebView or UITextView to display text in an e-book reader app?

I want to make an e-book reader iPhone app. Should I use UITextView or UIWebView to display the text? Which control is used by other e-book readers?
I would use a UIWebView, as it gives you much more flexibility in the presentation of the text. According to the UITextView Class Reference:
This class does not support multiple
styles for text. The font, color, and
text alignment attributes you specify
always apply to the entire contents of
the text view. To display more complex
styling in your application, you need
to use a UIWebView object and render
your content using HTML.
Also, UITextView uses scrolling to display large amounts of text (it inherits from UIScrollView); in an e-book reader, you will most likely want to paginate the content, so you will not want the scrolling behaviour.
UIWebView is much better solution than UITextView mainly due to support of rich formatting of its contents. On the other hand you will miss some very important functions which you get for free while using UITextView. I'm talking mostly about searching inside, changing contents size etc. All of this is possible with UIWebView but it's not straightforward - css & javascript are for the help here
Did you get highlight functionality for this as font size can change. Save them for future so that when ever he came to same page can see them
U should use UIWEB view ,as to provide paragraph and other functions of text are not supported by text view, u can directly implement html code and can make the app with proper view of text. So my suggestion is to use web view.