using Iphone sdk 3.1.2
I have a UITextView control with vertical and horizontal scrolling enabled. I want every line of text to display without wrapping so that the user can scroll horizontally to see it. The issue I have is that even with horizontal scroll enabled, the text wraps at the width of the iphone screen i.e.320 pixels.
How can I prevent wrapping?
Thanks
Use sizeWithFont: from the NSString UIKit additions to get each line's width, then set your UITextView's contentSize property to be slightly wider than the width of the longest line.
I had a problem trying this strategy, that arises when assigning a string to a UITextView's text property. On assignment, UITextView will set its contentSize.width to match the width of the view, and it will insert newlines into the assigned text string to wrap it to that width. You can set contentSize.width to the length of your longest line after assigning uitextview.text, and this gives the extra space in the scroll view, but the newlines stop the text from filling the new space.
If you set contentsize.width before loading your text into the view, the contentSize just gets reset when you do load your text.
I tried increasing the text view's frame size before loading, this works to let your long lines run on past the edge of the screen. But, you can't scroll, and the moment you reduce the frame size the newline mangling of your text and the readjustment of contentSize occurs again. The same occurs if any text is entered at all in the view.
Well, I'm convinced that uitextviews are simply not capable of or intended for horizontal scrolling at this point. I don't see how embedding a text view inside another scroll view could alleviate this either. Just have to do it in HTML ...
The solution is to turn off all the scroll options on the UITextView itself, then embed it in another UIScrollView. You can get actual code by searching on this term "DualScrollTextView" in google.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With