Creating a AutoLayout constraint using code

Source: Internet
Author: User

Creating a AutoLayout constraint using code

1. Steps for code creation constraints

2. Common methods of Code creation constraints

3. Principles of Code creation constraints

4. Reasons for disabling autoresizing

5. Set constraints relative to the status bar, using Self.toplayoutguide

6. Animating with AutoLayout

Get the height constraint (self.viewhconstraint)--Modify the constant value (self.viewhconstraint + = 100;)--In the animation [view layoutifneeded].

7. Summary of relevant knowledge about automatic layout:

7.1 autoresizing and AutoLayout are mutually exclusive and can only be used one at a time. Xib/storyboard uses AutoLayout by default, autoresizing is disabled. However, when you use code to add constraints to a UI control, Autoresizing is turned on by default and needs to be through view. Translatesautoresizingmaskintoconstraints = NO; turn off autoresizing to use AutoLayout in your code.

7.2 autoresizing can only set a constraint relationship between a control and its parent control, AutoLayout can set all constraints such as parent-child controls/sibling controls. Future projects will only use AutoLayout technology.

7.3 Autoresizing The outer box represents the parent control, and the inside box represents the currently selected control. There are also 6 lines, the outside of the 4 lines if selected, indicates that the child control and the parent control the spacing between the left and right, regardless of the screen to maintain the current value. If the 2 lines are selected, the size (height) of the child controls changes as the parent control's size changes.

7.4 Sizeclass is a new technology that appears after iOS8, which is not available if compatible with previous versions. Sizeclass the screen into 9 types, you can set a different screen to install a UI control, under different screens to the same control set different constraints, to the same picture box to set a different picture, to the same control set in a different font.

7.5 When adding a constraint using AutoLayout, in Xib Select a constraint, click on the property viewer, found that there is a priority (precedence, value is 1-1000, commonly used required1000,high750,lower50 three kinds), Indicates that when the same dimension is set, if more than one constraint conflicts, whichever is higher priority.

8. Controls such as Uibutton,uiswitch,uitextfield,uilabel,uiimageview, you can only set the X, Y value when using the AutoLayout layout, do not set the width height, because these controls have a default width and height.

9. The actual size of the screen when the iOS program is run is determined by the boot image (Launch.xib will be saved as a start-up diagram when it is run), and if the maximum size of the boot diagram is set to 4inch (320*568), then even 4.7inch (375*667) and 5.5inch ( 414*736) screen, still divides the screen into 320*568, which can cause the picture to become larger or blurry at most.

If the image size itself is not done according to IPhone6 and 6p (smaller than the size of 6 and 6p), the solution is: To change the boot image to use Launchimage, so that the actual size of 6 and 6p is also 4inch size, so you can achieve "false adaptation."

Creating a AutoLayout constraint using code

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.