-1

I added a UIScrollView to an empty ViewController, and added a vertical UIStackView to it. I set the constraint of the scrollview to 0 for each sides to fill the screen.

I added a bunch of buttons to the UIStackView, but when I run the code I cannot scroll the scrollview. It just does nothing on trying to scroll.

Here is the storyboard part:

enter image description here

Here is how it looks like in simulator:

enter image description here

I cant seem to figure it out. I assume I have to do this without adding a concrete height to the UIStackView because then that would resize the content...

What I want to achieve is like a ScrollView on Android.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
breakline
  • 5,776
  • 8
  • 45
  • 84
  • Do you understand what makes a scroll view scrollable in the first place? There is one rule for how to do it when not using auto layout, and another rule for how to do it when using auto layout. Which way are you using, and do you understand how to make the scroll view scrollable for that way? – matt Mar 05 '18 at 02:26
  • No, Im very new to IOS. Im an Android developer trying to learn IOS. I have autolayout on I guess (which is probably the default settings) – breakline Mar 05 '18 at 02:53

1 Answers1

0

This scrollview wont scroll as you have not added enough constraints for the scroll view to calculate the contentview size. Please try adding autolayout to the buttons. Each one. And pin the scrollview correctly. Its a must that the scollview should be able to calculate the content size correctly to work.

https://developer.apple.com/library/content/documentation/UserExperience/Conceptual/AutolayoutPG/WorkingwithScrollViews.html

Since you are new to iOS, may I suggest you looking at the tableview, seems its better suited on your usecase.

Athul George
  • 154
  • 11