Working with ScrollView and AutoLayout
Working with AutoLayout is very funny while you’re building your simple UI with UILabel, UIImageView and more, but when it’s time to implement a ScrollView, I can guarantee to you it’s not!

The first thing you must know when you want to implement a ScrollView is this, It’s very difficult even to Apple Engineers.
So, first we must drop a ScrollView in our View Controller. And now, we start to configure the constraints of the ScrollView and the children.
Setting the ScrollView constraints
First of all, we must adjust the ScrollView to the parent. So we click on the “Add new Constraint” button and we fill it with:

Now we drop a new View inside the ScrollView, this will be the container to our content.

Setting Content View constraints
Now, the second step is to set the constraints of the Content view inside the ScrollView.
First of all, we must define the width of the Content View, then the parent (ScrollView) will adjust to this width.
For this, we must set a “Equal widths” constraint in the Container View with the Parent View. We press Control + Drag to View and click in “Equal widths”

Now, we add new Constraints to the Content View to adjust it to the ScrollView.

We must have the View this way.

Adding content to Content View
Now, we just drop an UILabel inside the Content View. The constraints in the label are:

And magic happens! We have a ScrollView installed without any problem.

Important
If you forget to add content in the Content View, you must center horizontally and vertically the view, or Xcode will notify you an alert.
