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.
Step 1
Add a blank View Controller to your storyboard.
Step 2
In the Document Outline select the View Controller you just added.
Step 3
In the Document Inspector ensure that Use Auto Layout is checked.
Step 4
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.
Step 5
Add a View that fills the entire UIScrollView.
Step 6
Stretch the view to extend past the bottom of its parent Scroll View.
Step 7
Add a label to the top of that view inside the View Controller.
Step 8
Select the child View in the Document Outline.
Step 9
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).
Step 10
Add a label to the bottom of the View.
Step 11
Select the View again in the document outline.
Step 12
Drag the selected Child View back down to expose the top label, hiding the bottom label.
Step 13
Select the Scroll View in the document outline.
Step 14
Select the Pin option (bottom of the storyboard) and add the four horizontal and vertical constraints. Then click the Add 4 Constraints button.
Step 15
Select the View object in the Document Outline.
Step 16
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.
Step 16
Select the Vertical Constraint in the Document Outline that has the same value as the bottom vertical constraint in the previous step.
Step 17
In the Document Inspector (top right), change the constant to ‘0′.
Step 18
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.
Thanks a lot……
it’s very usefull for me.Please post some of the ios concepts step by step.Once again thank you….
Thank you so much. it helps a lot for beginners like me.
Also post other ios topics tutorials