How to add Scrollview constraint in IOS Xib file

Time:2020-6-28

When I started using Scrollview, I first tested it in Xib, and I couldn’t slide after adding sub layout. Later, after many attempts to solve the problem, I just recorded the process of my own solution.

Step 1: add Scrollview

Step 2: set up, down, left and right constraints for Scrollview

Step 3:Add a contentview to Scrollview, and set its upper, lower, left and right constraints. The width is the same as the parent layout (the width can also be different). The height is not set for the time being, because this feature will be used later to make its height adaptive content. At this time, I find that the small red arrow reports an error.

Step 4:Because the height is not determined, an error will be reported. Add a fixed size, and the constraint will not report an error. When the program is running, the size of contentviv will change according to your constraints, and the internal size will not affect your constraints.

Step 5:Add a child view to the contentview to expand the parent view so that it can slide.

Summary:

The frame of Scrollview is determined by constraints with the parent view

The height and width of contentsize of Scrollview are determined by containerview

The above is the whole process of realization.

The way to add the Scrollview constraint in this IOS Xib file is to share all the content with you. I hope to give you a reference, and I hope you can support developepaer more.