iOS Development-VFL language

Source: Internet
Author: User

Visual format Language, translated by the visual formatting language, is the language that Apple uses to simplify the AutoLayout code volume.
Instance:
(1) h:[(redview)]-12-[blueview (50)]
The initial letter indicates the horizontal direction, meaning there is a redview width of 72, the distance from the Redview right 12 points is a width of 50 blueview.

(2) H:[redview (>[email protected])
The width of the redview is greater than or equal to 60, the maximum width of the priority is 700 (the priority value is 1000, so 700 is met first)

(3) V:[redview][blueview (==redview)]
The redview is immediately below a blueview in the vertical direction, and its height is consistent with Redview.

(4) H:|-10-[redview]-[blueview]-[yellowview (>=20)]-|
The first and last two vertical bars represent the edges of the parent control, redview the distance from the default 10 points on the left side of the parent control, Redview to the right of the Blueview default interval, and the yellowview height is greater than or equal to 20 distance to the right of the Blueview default interval.

Application Examples:

CGFloatmargin =Ten;//Add horizontal direction constraint    NSString*VFL = @"h:|-margin-[buleview]-margin-|";nsdictionary*views = Nsdictionaryofvariablebindings (Buleview);nsdictionary*metrics = @{@"Margin": @ (margin)};Nsarray*constraints = [Nslayoutconstraint constraintswithvisualformat:vfl options:kniloptions metrics:metrics views:views]; [ Self. ViewAddconstraints:constraints];//Add vertical direction constraint    NSString*VFL2 = @"V:|-64-[buleview ()]";nsdictionary*views2 = Nsdictionaryofvariablebindings (Buleview);Nsarray*constraints2 = [Nslayoutconstraint constraintswithvisualformat:vfl2 options:kniloptions metrics:NilVIEWS:VIEWS2]; [ Self. ViewADDCONSTRAINTS:CONSTRAINTS2];


The code is as follows:

    UIView*buleview = [[UIViewAlloc]init]; Buleview. Translatesautoresizingmaskintoconstraints=NO; [Buleview setbackgroundcolor:[UicolorBluecolor]]; [ Self. ViewAddsubview:buleview];UIView*redview = [[UIViewAlloc]init]; Redview. Translatesautoresizingmaskintoconstraints=NO; [Redview setbackgroundcolor:[UicolorRedcolor]]; [ Self. ViewAddsubview:redview];CGFloatmargin =Ten;//Add horizontal direction constraint    NSString*VFL = @"H:|-margin-[buleview]-margin-[redview (==buleview)]-margin-|";nsdictionary*views = Nsdictionaryofvariablebindings (Buleview,redview);nsdictionary*metrics = @{@"Margin": @ (margin)};Nsarray*constraints = [Nslayoutconstraint constraintswithvisualformat:vfl options:kniloptions metrics:metrics views:views]; [ Self. ViewAddconstraints:constraints];//Add vertical direction constraint    CGFloatHeight = +;NSString*VFL2 = @"V:[buleview (height)]-margin-|";nsdictionary*views2 = Nsdictionaryofvariablebindings (Buleview);nsdictionary*METRICS2 = @{@"Margin": @ (margin), @"Height": @ (height)};Nsarray*constraints2 = [Nslayoutconstraint constraintswithvisualformat:vfl2 options:kniloptions metrics:metrics2 Views:    VIEWS2]; [ Self. ViewADDCONSTRAINTS:CONSTRAINTS2];//Add the remaining constraintsNslayoutconstraint *topconstraint = [Nslayoutconstraint constraintwithitem:redview attribute:NSLayoutAttributeTop Relatedby:nslayoutrelationequal Toitem:buleview attribute:nslayoutattributetop Multiplier:1.0constant0]; [ Self. ViewAddconstraint:topconstraint]; Nslayoutconstraint *bottomconstraint = [Nslayoutconstraint constraintwithitem:redview attribute: Nslayoutattributebottom relatedby:nslayoutrelationequal Toitem:buleview Attribute:nslayoutattributebottom Multiplier1.0constant0]; [ Self. ViewAddconstraint:bottomconstraint];

Why does the text still use the non-VFL language, because some constraints can not be expressed through the VFL. This Apple official has also indicated. But in the text you can fill in the nslayoutformatalignalltop| with option Nslayoutformatalignallbottom, can achieve that effect, you can not add nslayoutconstraint.

iOS Development-VFL language

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.