Press enter or click to view image in full size

2. After that, we add a UIView inside the UIScrollView (this view is an essential step to have the autolayout working correctly). I called it 'Content View' and added top, bottom, left and right constraints in regard with the scroll view. Besides that, I also added equal heights and widths with regard to the main view.
Press enter or click to view image in full size


3. The next step depends if you want to have either a vertical or a horizontal scroll. If you need a vertical scroll you'll need to set the 'Equal Heights Constraint' priority to 250. On the other hand, if a horizontal scroll is what you search for you'll have to set the 'Equal Widths Constraint' priority to 250.


4. The scroll view is now all set-up and ready to go! You can now start to add you content but you need to keep in mind that the 'Content View’ height can't be ambiguous. This means that each view that you had has to have an height constraint defined (height equals to X or less or equal to X) and that all the components (or at least you should have a continuous line of components from top to bottom) must have vertical spacing defined between themselves.
Join Medium for free to get updates from this writer.
Furthermore, the top-most and bottom-most components must have a top spacing and a bottom spacing, respectively, to the 'Content View’.
(if you're implementing a horizontal scroll you should read 'width' were I wrote 'height', 'horizontal spacing' instead of 'vertical spacing' and 'left-most'/'right-most' in place of 'top-most' and 'bottom-most'
5a) Vertical ScrollView — Component setup example
5b) Horizontal ScrollView — Component setup example
Using this method you'll also be able to support multiple device orientations as autolayout will work correctly in both orientations!