How to configure a UIScrollView with Auto Layout in Interface Builder.

Pradeep Chauhan
Jul 27, 2017 · 3 min read

As an iOS developer i saw many developers are stuck on scrollView with dynamic width and height. I’ll show you a good way of handling this things. In this approach we are doing this with storyboard only. As per your requirement create your design(Any height) it will automatically take care all things.

Follow this steps:

1. Create new project( eg. scrollViewAutoLayout).

2. After creating project go to Main.storyboard file.

3. Now you can see empty view controller on storyboard.

4. Drag scrollView from object library to view controller.

5. now it’s time to set constraint for scroll view.
6. Set scroll view constraint (top, bottom, leading and trailing) as (0,0,0,0).

7. Now update the frame.
8. Now we require contentView for scroll view.
9. Drag view from object library to scroll View.

10. now it’s time to set constraint for view(inside scroll view).

11. Set view constraint (top, bottom, leading and trailing) as (0,0,0,0).
12. Now you can see hierarchy like this view -> scroll view -> view(content view).

13. Now we need add more constraint for content view.

* Most important step *

14. Our content view must have equal width and equal height with parent view.

15. Now select height constraint of content view and set priority with low(250).

16. We are done with our setup.
17. Now you can design your view with any height.
18. Congrats you are done with scroll view with autolayout.

Download Demo

Join swift developer slack channel : https://join.slack.com/t/swift-developer/shared_invite/enQtMjI2MzEyMTU1MDU5LTQzODM2ZDYzNWI3ZWMzNWFmNWZkM2I0YzZkODg3NjJhN2M1N2NjYTUxN2M0YmY4NzVhNTliYTBjNWNmYmY2MDI

Thanks

Hope you learned something new today.

Enjoy!!

If you enjoyed reading this post, please share and recommend it so others can find it 💚💚💚💚💚💚 !!!!

You can follow me on Medium for fresh articles. Also, connect with me on LinkedIn.

If you have any comment, question, or recommendation, feel free to post them in the comment section below!

Pradeep Chauhan

Written by

Full Stack Developer

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade