1. Drag 1 Uiscrollview into the Viewcontroller and add a constraint to it
Constrain the upper and lower left edges to align with the superview
2. In ScrollView, drag in 1 uiview to make it orange for the sake of distinction.
3. Adding a constraint to a view
Constrain the upper and lower left edges to align with the superview
After adding these constraints, we found that there was an error, ignoring
4. To add a width constraint to the view, in this case, the effect is that scrollview can be scrolled vertically, not scrolled horizontally,
Therefore, you can constrain the width of the view to be the same as ScrollView
5. Next add a height constraint to the view
To update a frame
Happy to find that the constraint error has disappeared!
To verify that the ScrollView can slide correctly
We add a blue view to the ScrollView, add a width height constraint of 60,500, and then add to the left and top margins of the yellow view (that is, the superview of the Blue view)
At this point, all constraints are added to completion. Content that needs scrolling can be added in yellow view.
Click Run to see the effect
You can see that the ScrollView can slide as expected
Done!
How to add a constraint to Uiscrollview using AutoLayout