iOS Development-uiscrollview Auto Layout

Source: Internet
Author: User

Due to the complex characteristics of ScrollView itself, such as contentsize and contentinsets, it is very different from normal view in the automatic layout. To automate the layout of the ScrollView, you need to make a contentview as a scrollview scroll container. Here are the steps to automate the layout of ScrollView under IB:

First, create a basic view controller interface in Xib or storyboard (This step does not say) two, layout ScrollView

Drag a scrollview into the interface and set the desired area, fixed up or down:

Third, the layout contentview

Drag out a view (depending on the situation, this page may be used to display plain text, then just drag a label on it) as a child view of the Scrllview. This view will be used as the ScrollView Contentview to determine ScrollView's presentation. First, the upper and lower sides of the Contentview are fixed:

After the discovery will error, said Contentview the length of the width unknown. For normal view, fixed up and down left and right interval after the natural no longer need to set the length of the width, why still error? This is the difference between scrollview. Contentview as the content content of ScrollView, on its fixed up and down around the interval, in fact, only to set the content view and edge spacing function, just this role, the code and set the role of Contentinsets is the same! Therefore, the length and width of the contentview is not recognized. Apple has made a special deal with this step of ScrollView. So next, we're going to set the length of the Contentview.

Iv. Setting the Reference view

For Contentview, we have to constrain its length and width, in fact in code we also set the contentsize to the same effect. However, if you do not want to fix the long width, you need a reference view to determine the length of the width, because you can not scrollview to determine its length and width. So at this point, drag a view as a reference view and automatically layout it:

V. Setting Contentview length and width

Based on the reference view, the Contentview's length is automatically laid out. You can set the width of the two, the height wants to change dynamically, first set a value, and fixed the height, and then drag the height constraints into the code, through the code to dynamically change the height of the Contentview, that is, the ScrollView scroll height:

Pre-preparation is complete, can be a grand exhibition!

All of the next controls are laid out on contentview, just like normal views!

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

iOS Development-uiscrollview Auto Layout

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.