IOS 8 AutoLayout Getting Started

Source: Internet
Author: User

http://blog.csdn.net/asdfg13697116596/article/details/42562565

IOS 8 AutoLayout Getting Started
The layout of the user interface has become simpler since iOS6 brought the Auto layout feature. IOS8 is better to do
This article is mainly for beginners to share their recent learning AutoLayout experience. Let ' s start!
First, what is AutoLayout?
Simply put, automatic layout, when you rotate the screen or scale your UI to accommodate different sizes of screens, the program's view still looks nice, you can add or edit the constraints (constraints) in IB.
With AutoLayout enabled, you can check AutoLayout directly at Main.storyboard


2. Understand some of the AutoLayout's operations and features through a program
First drag in the storyboard three UIButton to create the following blocks, vertical screen display



(Note: In Xcode6, if you drag directly into UIView without adding constraint, when you drag into the next uiview it will directly cause the previous width to be zero, so when dragged into a uiview must be set to the reset to suggested constrains )


Do not make any changes, horizontal screen

But in fact, what you want to get is the following effect

3. What do you do?
Select the two button, press and hold, and then in the Editor menu, select Pin\widths equally

Similarly, choose Editor\pin\horizontal Spacing.

Tips: Of course you can also select these from the menu by selecting a button and then control-dragging to another button.

Next, for each of these three view applications:
Left: Top Space to Superview
Leading Space to Superview
Right: Top Space to Superview
Trailing Space to Superview
Lower part: Leading Space to Superview
Trailing Space to Superview
Bottom Space to Superview

?
At this point, the "T" type of constraint is still orange, indicating under-constrained.


Of course, from the document outline on the left, you can also see that there is a red arrow indicating an under constraint.

Next select three view, add heights equally.

At this point, run, OK!


4. Here are a few common questions:
Sometimes, we run the program to be prompted unable to simultaneously satisfy constraints, which represents a constraints conflict, that is, over-constrained. Generally speaking, an attempt to four constraints is enough, more must be removed, not more expensive, just right side good.
Intrinsic content size (intrinsic size):
When we drag into a button, we find that the button size is OK. Why is it? This is because it can automatically calculate its size based on text and background, and you can change its size by removing the width constraint and then setting your own preference size. If you want to cancel, simply select Editor \size to Fit Content.
Hugging priority (hug precedence) determines how much priority the view has to prevent itself from getting bigger.
In fact content hugging is to maintain the current view in its intrinsic content size, you can imagine adding an extra width constraint to view, This constraint attempts to keep the size of the view from getting larger.
Compression resistance priority (compression impedance prioritization) determines how much priority it has to prevent itself from getting smaller.
Content Compression resistance is to maintain the current view in his optimal size (intrinsic content size), which can be imagined as adding an extra width constraint to the view, This constraint tries to keep the size of the view from getting smaller.
These two concepts are very abstract, set themselves in the program, run a few times clear!

There are other properties that you need to check out in your help documentation. Good long-winded so much, logic is not strong, very miscellaneous, welcome everyone to criticize correct.

IOS 8 AutoLayout Getting Started

Related Article

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.