qnoid
qnoid

Reputation: 2376

How to setup vertical only scrolling programmatically

On interface builder there is an option to limit a UIScrollView's scrolling to either vertical or horizontal.

However I couldn't find a property or a method in UIScrollView to enable such behavior.

Is it achieved through some other way or am I missing something?

alt text

Upvotes: 3

Views: 3908

Answers (3)

Steve
Steve

Reputation: 1199

In addition to setting the contentSize width as mentioned, you should also set the scrollView.alwaysBounceHorizontal = NO to stop the horizontal bounce which will still be on.

The solution is from the question already answered:

UIScrollView *scrollView;
CGRect size = scrollView.contentSize;
size.width = CGRectGetWidth(scrollView.frame);
scrollView.contentSize = size;
scrollView.alwaysBounceHorizontal = NO;

Upvotes: 2

Brian
Brian

Reputation: 15706

I don't think that limits scrolling in those directions, it just determines whether the scroll indicators are shown (so the properties would be showsHorizontalScrollIndicator and showsVerticalScrollIndicator).

Upvotes: 1

jer
jer

Reputation: 20236

Set your contentSize property such that its width is the same as your scrollview's width. Tada! No more horizontal scrolling.

Upvotes: 2

Related Questions