The Uiscrollview in Storyboard, Xib uses AutoLayout to enable it to scroll

Source: Internet
Author: User

When using storyboard and xib, we often use ScrollView, as well as automatic layout autolayout, but ScrollView and AutoLayout are used in a relatively complex sense. According to the practice, I say my understanding, in the storyboard or Xib, ScrollView determines the size of the contentsize based on the size of the view below it.

Take a look at the effect

1. Create a project, drag a scrollview into the storyboard, such as

2. Select ScrollView to add the constraint. 3. Drag a view onto the ScrollView, then add the upper and lower left and right around the constraint. 4. After the addition, may report a mistake, for example, this temporarily do not take care of.

5. Let's make sure that we need to scroll horizontally or vertically, or both horizontally and vertically.

A. Both the horizontal and vertical directions need to be scrolled without adding

B. Horizontal direction scrolling requires the following constraint to be added

C. The following constraint needs to be added in the vertical direction 6. Let's take a horizontal scroll for example, we need to determine the width we want, and add a fixed width constraint. 7. If you want to dynamically set the width of the scrollview, that is, set the value of the view's width constraint, we pull it into a property and then modify its value. 8. If the width is determined, it can be modified in-(void) Updateviewconstraints This method, or it can be modified elsewhere. This will be OK. You can add a view by code and then you can scroll through the page. Automatic layout needs to be more practical, there are a lot of details to pay attention to.

To add a child control to the ScrollView-from the yearning to the next row

0. Set the upper and lower bounds of the ScrollView distance controller view margin is 0 (determines the size of the frame)

1. To add a content view to ScrollView

2. Constrain the contents of the view to the left upper right distance from the parent control to 0

3. Height of view that constrains dead content

4. Constraint content view is centered horizontally in the ScrollView (vertical slide)

5. Adding controls-from top to bottom

6. Remove the constraint of the content view to the height of the dead

7. Constrain the space between the view distance of the last control view from the bottom

The Uiscrollview in Storyboard, Xib uses AutoLayout to enable it to scroll

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.