AutoLayout of Storyboard Way ScrollView

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. You need to add the following constraint 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. Select View to update frame

8. 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.

9. If the width is determined, it can be modified in-(void) Updateviewconstraints This method, or it can be modified elsewhere.

10. Now running, you can scroll horizontally. The vertical direction of scrolling is similar to the setting for horizontal scrolling. Let's add two views, drag a view (I set it to gray) to the layout, and add constraints, such as

11. Drag and drop a view, set the background color to red, set the frame to what we need, and my side will set X to 600.

12. We add a constraint to the second view, such as

13. We also need to set a constraint, that is, the second view distance Superview distance, is the second view of the leading constraints

14. Then pull the constraint leading property, set his value in-(void) updateviewconstraints

Such as

This will be OK.

Automatic layout needs to be more practical, there are a lot of details to pay attention to.

Demo address for this example: http://download.csdn.net/detail/h1101723183/8253159

Vertical demo in http://download.csdn.net/detail/h1101723183/8266503

AutoLayout of Storyboard Way ScrollView

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.