Add line breaks when displaying a long string in UIWebView - iphone

When displaying a paragraph with some long strings without line breaks in an UIWebView, the size of the character is too small for reading, as show in the following pic. Is there anyway to automatically add line breaks in the long strings as in the UILabel? Thanks in advance!
ps. the UIWebView is used to display an email body.

set the css as : style="word-break:break-all" to solve this problem

Simply NO. UIWebView is made to parse HTML-Markup. The breaking has to be done there. \n will do it.
Other than that, you should rethink your HTML-Box-Model being responsive.
If you only want to display text, then use UITextView instead of UIWebView and switch to UIWebView, if its HTML. I think Mail.app on iOS does it like that. UITextView text is appropriately scaled.

Related

printing text as a paragraph(indentation) in uitextview in iphone

A basic functionality I am trying to implement in UITextView.
I have a text (NSString) and I am trying to place in to the text field as a paragraph (indentation). Is it possible? I have seen many links but none of them have an exact answer.
We have a property named textAlignment but it is for left, right or center not indention.
Can anyone suggest how to implement this?
You should consider using a UIWebView if your displayed text has formatting. Using textViews and labels quickly renders the code to complex.
Possible solution in this post - as the first answer suggested, use a UIWebView.

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.

Formatting in a UITextView

im having problems with formatting for a UITextView. my app pulls in XML, saves some of it to a string , and then displays the text in a UITextView.
it understands if you put a return in there, and it starts a new line. but i want to put paragraphs in there, any idea how i can pass that information without doing multiple UITextViews
Thanks :)
If you are converting to text from XML content, then it is probably easier to use a UIWebView and format using html.
If you want total control of formatting, then you need to move to using Core Text (3.2/iPad).

UILabel alignment

In my app I need to show a large volume of data(news) to the user. I tried using UIWebView to show up the news data. It worked fine but the performance was low. UIWebView takes time to show up all the data.
So I started using UILabel to show up the data. This worked fine with no performance issue. But the problem is when ever a line ends the UIWebView automatically puts spaces in between to align the text properly. But UILabel is not doing the same. So the text is not aligned properly. how do we get the text aligned properly as it is done in UIWebView
Thanks In Advance!!!
I think the answer to this is to build your own text layout using UIKit's NSString's extentions: drawAtPoint:InFont as recommended in this SO question.
Try using a UITextView. This should wrap text a little nicer than the UILabel.

Searching text from UITextView in iPhone

I'm developing an application for the iPhone where some text is shown in a UITextView. I want to search for a specific word in the text and then show the text with that specific word colored. If anyone can help me solve this, I'll be very glad.
UITextView does not allow any formatting of the text within it. If the text is static (i.e. doesn't need to be edited), use a UIWebView instead; that will allow you to apply HTML formatting.
If a web view isn't an option, your best bet will be to try to calculate where the text in question will fall in the text view and then draw some sort of highlight around it. NSString has some methods to calculate how much space you need to draw a given string on screen; by being very, very clever with those methods, you may be able to work out where the word you're trying to highlight is. Unfortunately, this will not be at all simple.
If you do come up with a solution, everyone here would probably love to hear about it!