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

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

if you have any query feel free to ask.