__weaktypeof(self) weakself =Self ; UIView* Tempview =[[UIView alloc]init]; Nsinteger Count=Ten;//set the number of view in a rowNsinteger margin =Ten;//set the distance apartNsinteger height = -;//set the height of the view for(inti =0; I < count; i + +) {UIView* View =[[UIView alloc]init]; View.backgroundcolor=[Uicolor Browncolor]; [Self.view Addsubview:view]; if(i = =0) {[View mas_makeconstraints:^ (Masconstraintmaker *Make ) {Make.left.equalTo (Weakself.view). offset (margin); Make.centerY.equalTo (Weakself.view); Make.height.mas_equalTo (height); }]; } Else if(i = = count-1) {[View mas_makeconstraints:^ (Masconstraintmaker *Make ) {Make.right.equalTo (Weakself.view). Offset (-margin); Make.left.equalTo (tempview.mas_right). offset (margin); Make.centerY.equalTo (Tempview); Make.height.equalTo (Tempview); Make.width.equalTo (Tempview); }]; } Else{[View mas_makeconstraints:^ (Masconstraintmaker *Make ) {Make.left.equalTo (tempview.mas_right). offset (margin); Make.centerY.equalTo (Tempview); Make.height.equalTo (Tempview); Make.width.equalTo (Tempview); }]; } Tempview=view; [View layoutifneeded]; }
Ios-masonry usage