Automatic Layout of IOS development-VFL language and ios Layout-vfl
VFL is an abstract language developed by Apple to simplify Autolayout encoding. It is worth learning and learning about the pure code enthusiast.
1. What is VFL?
VFL stands for Visual Format Language, which is translated as "Visual Format Language ".
2. VFL example:
H: [cancelButton (72)]-12-[acceptButton (50)]
CanelButton is 72 in width, acceptButton is 50 in width, and the distance between them is 12.
H: [wideView (>=60 @ 700)]
If the width of the wideView is greater than or equal to 60 point, the priority of the constraint is 700 (the maximum priority is 1000, and the higher the priority, the more advanced the constraint is)
V: [redBox] [yellowBox (= redBox)]
In the vertical direction, there is a redBox first, followed by a yellowBox with a height equal to the redBox height.
H: |-10-[Find]-[FindNext]-[FindField (> = 20)]-|
In the horizontal direction, the default interval between Find and the left edge of the parent view is the width, followed by the default interval between FindNext and Find;
After that, the FindField with a width not less than 20 is used. the spacing between the FindNext and the right edge of the parent view is the default width. (Vertical line "|" indicates the superview edge)
3. Use of VFL:
Use VFL to create a constraint Array
+ (NSArray *) constraintsWithVisualFormat :( NSString *) format options :( NSLayoutFormatOptions) opts metrics :( NSDictionary *) metrics views :( NSDictionary *) views;
Format: VFL statement
Opts: Constraints
Metrics: the specific value used in the VFL statement.
Views: controls used in VFL statements
Create a dictionary (containing controls used in VFL statements ).
NSDictionaryOfVariableBindings (...)
The following example shows how to use this function:
4. Examples of VFL code exercises:
Requirement: we need to achieve the following results.
Add 2 Views, 1 blue and 1 red at the bottom of the controller view
The width and height of the two views are always equal, and the height is equal to 50.
The distance between the left, right, and bottom of the parent control and the two views is equal to or equal to 30.
Code implementation:
Source code Baidu cloud download link: http://pan.baidu.com/s/1eS13VAa password: Drawing 1u
Display Effect (rotate directly to a horizontal screen ):
Note:
Reprinted with the source: http://www.cnblogs.com/goodboy-heyang/p/5359857.html, respect for labor results.