"Basic Syntax"
The syntax of the VFL is H: and V: opening, which represents horizontal and vertical.
Next, if you want to involve distance, use |-x-,x as the distance point.
For views, surround with [], for example [Blueview].
① The following statement implements the edge 20 points of the blueview horizontal direction around each distance controller:
h:|-20-[blueview]-20|
② If you want to specify a wide height, fill in the constant value with parentheses after the view name, the following code implements the Blueview distance to the left 20 points, the width is fixed to 120 points:
H:|-20-[blueview (20)]
③ If you want to specify an equality relationship, such as the width of the redview and the Blueview equal, write [Redview (==blueview)] in the condition that begins with H:.
④ If the multiplication calculation is present and the VFL cannot be used, the Nslayoutconstraint constraintwithitem should be used::::: Method, the formula is firstitem.x = (seconditem.x + constant) * Multiplier,x The calculation amount specified for attribute, note that this constraint should be added to their public parent node.
"Implementation Method"
Use Constraintswithvisualformat:::: Method:
/** FORMAT:VFL Statement options: Alignment METRICS:VFL used variable VIEWS:VFL view */+ (Nsarray *) Constraintswithvisualformat: (NSString *) format options: (nslayoutformatoptions) OPTs metrics: (nsdictionary *) metrics Views: (Nsdictionary *) views;
① If no alignment is required, the options are filled in 0.
②views is the basis for the actual view in the VFL, such as @{@ "Redview": Self.redview}, when Redview is present in the VFL, The system will find the Self.redview through the views dictionary, thus realizing the size of the modified Self.redview.
③metrics is a variable used in the VFL, for multiple occurrences of a value, you can replace it with a variable, and then specify the value of the variable in metrics.
Instance
The following code implements the Blueview distance controller view Edge left, middle, and right 20 points, Redview under Blueview 20 points, right-aligned, width is half of blueview.
It is important to note that autoresizing is disabled.
-(void) viewdidload {[Super viewdidload]; UIView *blueview = [[UIView alloc] init]; Blueview.backgroundcolor = [Uicolor Bluecolor]; [Self.view Addsubview:blueview]; UIView *redview = [[UIView alloc] init]; Redview.backgroundcolor = [Uicolor Redcolor]; [Self.view Addsubview:redview]; Blueview.translatesautoresizingmaskintoconstraints = NO; Redview.translatesautoresizingmaskintoconstraints = NO; Nsarray *blueviewhori = [Nslayoutconstraint constraintswithvisualformat:@ "h:|-20-[blueview]-20-|" options:0 metrics: Nil views:@{@ "Blueview": Blueview}]; [Self.view Addconstraints:blueviewhori]; Nsarray *blueredverti = [Nslayoutconstraint constraintswithvisualformat:@ "V:|-20-[blueview ()]-20-[redView (= = Blueview)] "Options:nslayoutformatalignallright metrics:nil views:@{@" Blueview ": blueview,@" RedView ": RedView}]; [Self.view Addconstraints:blueredverti]; Nslayoutconstraint *redviewwidthconstraint = [Nslayoutconstraint constraintwithitem:rEdview attribute:nslayoutattributewidth relatedby:nslayoutrelationequal toitem:blueview attribute: Nslayoutattributewidth multiplier:0.5 constant:0]; [Self.view Addconstraint:redviewwidthconstraint]; }
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
(88) The initial language of the VFL-implementation layout