Wondering how to create, populate and configure a Scroll View inside a View Controller using Storyboards in Xcode 5? This is for you.
Let’s get started.
Add a blank View Controller to your storyboard.
In the Document Outline select the View Controller you just added.
In the Document Inspector ensure that Use Auto Layout is checked.
Drag a UIScrollView onto the view. In this example, I let it expand to consume the whole View Controller. If you wish, re-size as required.
Add a View that fills the entire UIScrollView.
Stretch the view to extend past the bottom of its parent Scroll View.
Add a label to the top of that view inside the View Controller.
Select the child View in the Document Outline.
Vertically expand the view beyond the end if it’s parent Scroll View. Then drag it upwards to expose the bottom half of the view (the bit that will be below the screen in the app which the user will be able to scroll to).
Add a label to the bottom of the View.
Select the View again in the document outline.
Drag the selected Child View back down to expose the top label, hiding the bottom label.
Select the Scroll View in the document outline.
Select the Pin option (bottom of the storyboard) and add the four horizontal and vertical constraints. Then click the Add 4 Constraints button.
Select the View object in the Document Outline.
Click the Pin button and select all four horizontal and vertical constraints (the bottom vertical constraint value will vary based on how far you expanded the child View controller). Check the Width and Height. In my case it’s lucky number 113, but yours will look different depending on how long you made the view. Take a mental note of this number.
Select the Vertical Constraint in the Document Outline that has the same value as the bottom vertical constraint in the previous step.
In the Document Inspector (top right), change the constant to ‘0′.
Finally, run your app and test the scrolling, then give me feedback and share this with someone else who might find it useful 🙂
Thanks for reading, I hope you found this useful. If you want to get notifications of future posts, please join our London App Developer community.