UITextView horizontal scrolling

I have a UITextView that wraps long text words and has a vertical scrolling feature. How can I disable word wrap and enable horizontal scrolling while maintaining vertical scrolling?


source to share

1 answer

I've only seen this answer on stackoverflow.

Let's say I want a scrollable width of 600 and an apparent width of 250.

The first step is to make the UITextView as wide as the area you want to scroll. So what would you put in the contentSize, in this case 600.

Then the right-hand insert is set to the difference between the actual width and the width you wanted. In this case 350.

This way the cursor is constrained to the required width, but there is text visible to the right of the desired width, after all, UITextView IS 600 pixels wide.

Now that the really hacking bit comes, don't read if you are sensitive or have a weak stomach.

Get the UI image to the right where the UITextView should end. Insert it into the NIB as a UIImage view and put it back in place, making sure it sits on top of the UITextView.

When the view is displayed, the cutout is on top of the UITextView and hides the text overflow.



All Articles