3

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

qnoid
  • 2,346
  • 2
  • 26
  • 45

3 Answers3

2

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

jer
  • 20,094
  • 5
  • 45
  • 69
2

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;
Community
  • 1
  • 1
Steve
  • 1,201
  • 8
  • 14
1

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).

Brian
  • 15,599
  • 4
  • 46
  • 63