Add constraint plots and points for Uiscrollview using AutoLayout

Source: Internet
Author: User

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

Finally, all the constraints see

Uiscrollview Add constraint points:

The constraint relationship between 1.scrollView and ScrollView Superview is used to determine the ScrollView frame

The constraint relationship of "Contentview" (blue view in this example) in 2.scrollView is used to determine the contentinsets of ScrollView

The width and height of the 3.contentView are used to determine the ScrollView contentsize

By understanding these 3 points, you can happily add a constraint to the ScrollView

Add constraint plots and points for Uiscrollview using AutoLayout

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.