VFL Syntax-Basics

Source: Internet
Author: User

1 #import "ViewController.h"2 3 @interfaceViewcontroller ()4 {5UIView *_redview;6UIView *_blueview;7UIView *_cyanview;8 }9 @endTen  One @implementationViewcontroller A  -- (void) Viewdidload { - [Super Viewdidload]; the     //1. No longer need to set frame coordinates -_redview =[[UIView alloc] init]; -_redview.backgroundcolor =[Uicolor Redcolor]; -     //2. May conflict with Autoresizingmask +_redview.translatesautoresizingmaskintoconstraints =NO; - [Self.view Addsubview:_redview]; +      A_blueview =[[UIView alloc] init]; at_blueview.backgroundcolor =[Uicolor Bluecolor]; -_blueview.translatesautoresizingmaskintoconstraints =NO; - [Self.view Addsubview:_blueview]; -      -_cyanview =[[UIView alloc] init]; -_cyanview.backgroundcolor =[Uicolor Cyancolor]; in_cyanview.translatesautoresizingmaskintoconstraints =NO; - [Self.view Addsubview:_cyanview]; to      +     //Constraints -  the     /* * 1.view1: Set Constraints on Objects View1 this object $ 2.attribute: Refers to View1.attribute set what kind of constraintPanax Notoginseng 3.relatedBy: Relationship equals - 4.view2: Referential the 5.attribute:view2.attribute + 6.multiplier: Multiplier factor A 7.constant: Deviation value the       + 8. Calculation: VIEW1.ATTR1 = View2.attr3*multiplier + constant -     */ $      $     //Create a left spacing constraint from a parent view -Nslayoutconstraint *conleft = [Nslayoutconstraint constraintwithitem:_redview attribute:nslayoutattributeleft Relatedby:nslayoutrelationequal ToItem:self.view Attribute:nslayoutattributeleft Multiplier:1.0constant -]; -     //Create a right spacing constraint theNslayoutconstraint *conright = [Nslayoutconstraint constraintwithitem:_redview attribute:nslayoutattributeright Relatedby:nslayoutrelationequal ToItem:self.view attribute:nslayoutattributeright Multiplier:1.0constant:- -]; -     //Create top spacingWuyiNslayoutconstraint *contop = [Nslayoutconstraint constraintwithitem:_redview attribute:nslayoutattributetop Relatedby:nslayoutrelationequal ToItem:self.view attribute:nslayoutattributetop Multiplier:1.0constant -]; the     //Create a height constraint -Nslayoutconstraint *conheight = [Nslayoutconstraint constraintwithitem:_redview attribute:nslayoutattributeheight Relatedby:nslayoutrelationequal ToItem:self.view attribute:nslayoutattributeheight Multiplier:0.2constant0]; Wu      -     //Create bottom Spacing About     //nslayoutconstraint *conbottom = [Nslayoutconstraint constraintwithitem:_redview attribute: Nslayoutattributebottom relatedby:nslayoutrelationequal ToItem:self.view Attribute:nslayoutattributebottom multiplier:1.0 constant:-20]; $      - [Self.view Addconstraints:@[conleft,conright,contop,conheight]]; -      -      A      +      the     //NSLog (@ "%@", Nsstringfromcgrect (_redview.frame)); -      $     //Create a left spacing constraint from a parent view theNslayoutconstraint *blueleft = [Nslayoutconstraint constraintwithitem:_blueview attribute:nslayoutattributeleft Relatedby:nslayoutrelationequal ToItem:self.view Attribute:nslayoutattributeleft Multiplier:1.0constant -]; the     //Create a right spacing constraint theNslayoutconstraint *blueright = [Nslayoutconstraint constraintwithitem:_blueview attribute:nslayoutattributeright Relatedby:nslayoutrelationequal ToItem:self.view attribute:nslayoutattributeright Multiplier:0.5constant:-Ten]; the     //Create top spacing -Nslayoutconstraint *bluetop = [Nslayoutconstraint constraintwithitem:_blueview attribute:nslayoutattributetop Relatedby:nslayoutrelationequal Toitem:_redview Attribute:nslayoutattributebottom Multiplier:1.0constant -]; in     //Create a height constraint the     //nslayoutconstraint *blueheight = [Nslayoutconstraint constraintwithitem:_redview attribute: Nslayoutattributeheight relatedby:nslayoutrelationequal ToItem:self.view Attribute:nslayoutattributeheight multiplier:0.2 constant:0]; the      About     //Create bottom Spacing theNslayoutconstraint *bluebottom = [Nslayoutconstraint constraintwithitem:_blueview attribute:NSLayoutAttributeBottom Relatedby:nslayoutrelationequal ToItem:self.view Attribute:nslayoutattributebottom Multiplier:1.0constant:- -]; the      the [Self.view Addconstraints:@[blueleft,blueright,bluetop,bluebottom]]; +      -      the     Bayi      the      the     //Create a left spacing constraint from a parent view -     //nslayoutconstraint *cyanleft = [Nslayoutconstraint constraintwithitem:_cyanview attribute:nslayoutattributeleft Relatedby:nslayoutrelationequal Toitem:_blueview attribute:nslayoutattributeright multiplier:1.0 constant:20]; -Nslayoutconstraint *cyanleft = [Nslayoutconstraint constraintwithitem:_cyanview attribute: Nslayoutattributeleftmargin relatedby:nslayoutrelationequal ToItem:self.view Attribute:nslayoutattributeright Multiplier0.5constantTen]; the     //Create a right spacing constraint theNslayoutconstraint *cyanright = [Nslayoutconstraint constraintwithitem:_cyanview attribute:nslayoutattributeright Relatedby:nslayoutrelationequal ToItem:self.view attribute:nslayoutattributeright Multiplier:1.0constant:- -]; the     //Create top spacing theNslayoutconstraint *cyantop = [Nslayoutconstraint constraintwithitem:_cyanview attribute:nslayoutattributetop Relatedby:nslayoutrelationequal Toitem:_redview Attribute:nslayoutattributebottom Multiplier:1.0constant -]; -     //Create a height constraint the     //nslayoutconstraint *blueheight = [Nslayoutconstraint constraintwithitem:_redview attribute: Nslayoutattributeheight relatedby:nslayoutrelationequal ToItem:self.view Attribute:nslayoutattributeheight multiplier:0.2 constant:0]; the      the     //Create bottom Spacing94Nslayoutconstraint *cyanbottom = [Nslayoutconstraint constraintwithitem:_cyanview attribute:NSLayoutAttributeBottom Relatedby:nslayoutrelationequal ToItem:self.view Attribute:nslayoutattributebottom Multiplier:1.0constant:- -]; the      the [Self.view Addconstraints:@[cyanleft,cyanright,cyantop,cyanbottom]]; the 98 } About  --(void) Touchesbegan: (Nsset *) touches withevent: (Uievent *)Event101 {102NSLog (@"%@", Nsstringfromcgrect (_redview.frame));103 }104  the- (void) didreceivememorywarning {106 [Super didreceivememorywarning];107     108 }109  the @end

VFL Syntax-Basics

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.