Reputation: 43
I am trying to make a view controller scrollable because there is not enough room on the screen at one time to fit everything. I have checked out links from Google on how to do this http://www.ongraph.com/blog/scroll-view-in-swift and http://makeapppie.com/2014/12/11/swift-swift-using-uiscrollview-with-autolayout/ The only thing is that these examples use images while I on the other hand want to use buttons. How would I go about doing this? Thanks!
Upvotes: 2
Views: 8742
Reputation: 131503
You want to create a scroll view and put it inside your view controller's main view. Make the scroll view's content view as large as you need it to be, and then put your content in that content view. The trick is that you have to set the scroll view's contentSize property, and you can't do that in Interface Builder without some trickery.
Here is an SO post where I outline how to set up a scroll view in some detail.
How do I alter the position of a UIImage inside a UIImageView
In that post the asker's goal was to let the user scroll the position of an image view, but you can put any content you want in the scroll view's content view.
I created a demo Swift project that illustrates a couple of different ways of setting the scroll view's contentSize. If you get stuck post a comment and I'll try to find the time to write it up in my developer's blog and post the code to Github.
Upvotes: 3