Ios-autolayout a strong text

Source: Internet
Author: User

Thank the author for sharing! Declaration Reprint address: http://blog.csdn.net/xyt8023y/article/details/47059019

AutoLayout is an automatic layout method following autoresizing, which solves the problem that autoresizing cannot handle the relationship between controls.
AutoLayout is set in storyboard by the bottom toolbar, and the bottom toolbar is only displayed with the AutoLayout permission checked.

The left-to-right three buttons are alignment, pinning, and dimension repair, respectively.
"Align"

Neither the first column nor the second column can be selected because they are relative properties and require more than one control.
The first column is left, right, top, bottom, and the following value is the offset.
The second column is horizontal, center-aligned, or line-aligned relative to another control.
The third column can be directly selected, and is aligned horizontally and vertically relative to the screen.

"Pin"

The above four properties are consistent with the autoresizing, representing a fixed distance of four directions, the small arrow on the right represents the relative to which view, it should be noted that if B wants to be relative to a layout, let B's top distance A of the bottom 20 points, then in B to choose relative to a, A must be selected on the top of B: Select the correct view in the drop-down box, for convenience, you should give each view a name.


The following equal widths and equal heights all require two or two more view to achieve their wide, high consistency.
Note In the first column at the end of the constrain to margins is the default check, IOS8 has a new feature, around a certain margin, if you want to calculate relative to the edge of the screen, you should uncheck the check, be sure to pay attention.

"Resolve Auto Layout Issues"

When the result of the AutoLayout constraint is inconsistent with the current display, clicking Update frames Updates the view.

"Attention Point"
1. Try not to set frame after using AutoLayout, otherwise there may be strange problems.
2.AutoLayout appears red for error, indicates missing constraint, yellow is warning, update frames should be updated.

Change constraint implementation proportional relationship
Sometimes there is a need, a relative to the screen center, B and a right alignment, and B is the width of a half, the focus is the last proportional relationship.
There are two main ways to implement, before introducing the method of changing constraints, click on any one of the constraint line, see the right side of the interface:

Here is the calculation of the relationship, the formula is first = (Second + Constant) * Multiplier, assuming this is a width relationship, and the width of the blueview is fixed, then according to the above formula, the system will automatically solve the redview width, and vice versa.
★ Implementation Method One: Using the width relationship
For a, b add equal widths constraints, check constraint lines, change multiplier, make viewb.width = (viewa.width + 0) * 0.5, or meet viewa.width = (viewb.width + 0) * 2.
★ Implementation Method Two: using the center alignment
Because a is centered relative to the screen, simply align the left side of B with the centerline of the screen.
The implementation method is Superview.center x = (viewb.leading + 0) * 1, because the center X of the parent view does not change, so only the left side of the VIEWB changes, which enables alignment with the centerline.

"Handling of Controller view scaling changes"
If the controller view is stretched and the child controls are not changed relative to the screen, you can choose to follow the center line of the screen.

Ios-autolayout a strong text

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.