1 //2 //VIEWCONTROLLER.M3 //E01. Masonry basic Use4 //5 //Created by Apple on 15/8/8.6 //Copyright (c) 2015 Apple. All rights reserved.7 //8 9 #import "ViewController.h"Ten One //Define this constant if you want to use masonry without the ' mas_ ' prefix A //if you want to omit the Mas_ prefix when using masonry, define the following macro - #defineMas_shorthand - the - //Define this constant if your want to enable auto-boxing for default syntax - //If you want Equalto to have the auto-boxing function By default, define the following macro - #defineMas_shorthand_globals + - #warningmark-above two macros must be defined on the top of the Masonry.h header file + #import "Masonry.h" A at @interfaceViewcontroller () - - @end - - @implementationViewcontroller - //Chained Language in- (void) Viewdidload { - [Super Viewdidload]; to +UIView *bleuview =[[UIView alloc] init]; -Bleuview.backgroundcolor =[Uicolor Bluecolor]; the [Self.view Addsubview:bleuview]; * $ //to add a constraint to BlueviewPanax Notoginseng[Bleuview makeconstraints:^ (Masconstraintmaker *Make ) { -Make.left.equalTo (self.view.left). Offset ( -); theMake.top.equalTo (self.view.mas_top). Offset ( -); +Make.right.equalTo (self.view.mas_right). Offset (- -); AMake.bottom.equalTo (Self.view.mas_bottom). Offset (- -); the + //when you add a constraint to a control, the properties of this control, as well as the properties of the reference control, can be omitted without writing - //Make.left.equalTo (Self.view). offset (+); $ //Make.top.equalTo (Self.view). offset (+); $ //Make.right.equalTo (Self.view). Offset ( -50); - //Make.bottom.equalTo (Self.view). Offset ( -50); - the //when you add a constraint to a control, the same control is referenced, and the properties of the reference are the same as the properties to which you want to add the constraint control, and their offset values are the same, the properties can be set continuously - //Make.left.top.equalTo (Self.view). offset (+);Wuyi //Make.bottom.right.equalTo (Self.view). Offset ( -50); the - //Make.edges.equalTo (Uiedgeinsetsmake () , (a); Wu - //add padding to Blueview Mas_equalto you can convert basic data types to object types (this process is called boxing) About //Make.edges.mas_equalTo (Uiedgeinsetsmake () , (a); $ - - }]; - A //update constraint for BLUEVEIW-if the same constraint property has been added when the constraint is being updated, this method overrides the preceding constraint, using the new constraint + //constraint violations may occur if there are new constraint properties added to this method, but if the control lacks constraints before this method, this method can also add the missing constraints the[Bleuview updateconstraints:^ (Masconstraintmaker *Make ) { - //Make.left.equalTo (Self.view). offset (+); $ //Make.width.equalTo ($);//can't use the //Make.bottom.equalTo (self.view.mas_bottom). Offset ( -50); the the }]; the - //Delete all Blueview constraints, (if nothing is done inside the method, is to delete all constraints before Blueview, if you add a constraint in this method, you will delete the previously added, and then add the new constraint again) in[Bleuview remakeconstraints:^ (Masconstraintmaker *Make ) { theMake.edges.mas_equalTo (Uiedgeinsetsmake ( Max, Max, -, -)); the About }]; the } the the @end
Basic use of Masonry