How to disable horizontal scrolling of UIScrollView?

Rahul Vyas picture Rahul Vyas · Jun 30, 2009 · Viewed 112.3k times · Source

I have a UIView like iPhone's Springboard. I have created it using a UIScrollView and UIButtons. I want to disable horizontal scrolling on said scrollview. I want only vertical scrolling. How do I accomplish this?

Answer

Dave DeLong picture Dave DeLong · Jun 30, 2009

You have to set the contentSize property of the UIScrollView. For example, if your UIScrollView is 320 pixels wide (the width of the screen), then you could do this:

CGSize scrollableSize = CGSizeMake(320, myScrollableHeight);
[myScrollView setContentSize:scrollableSize];

The UIScrollView will then only scroll vertically, because it can already display everything horizontally.