What is the best way to disable horizontal scroll of UIScrollView?

Hiren Prajapati picture Hiren Prajapati · Dec 4, 2017 · Viewed 7.5k times · Source

In UIScrollView, I have content height and width greater than scrollview's size. So basically it can scroll horizontally and vertically. What I want is to scroll vertically only and I manage horizontally scroll using an UIButton by using below code.

 [scrlViewQuestion setContentOffset:CGPointMake(questionWidth, 0) animated:YES];

Preventing horizontal scrollview, one can just set scrollview content width lesser than scrollview size but in my case scrollview content width is greater than its size? So what is the best way to solve this?

Answer

ManjunathK picture ManjunathK · Nov 9, 2018

Content UIView width should be equal to the width of UIScrollView's superview for instance, not UIScrollView itself.

enter image description here