Masonry self-adapting screen

Source: Internet
Author: User

1 #import "RootViewController.h"2 #import "Masonry.h"3 @interfaceRootviewcontroller ()4 5 @end6 7 @implementationRootviewcontroller8 9- (void) Viewdidload {Ten [Super Viewdidload]; One      A #pragmaMark Lable -     //add a constraint without setting the frame -UILabel *lable = [UILabelNew]; theLable.backgroundcolor =[Uicolor Redcolor]; -     //Add to Parent view to layout when view is added - [Self.view addsubview:lable]; -     //layouts, Implementing layout methods +[Lable mas_makeconstraints:^ (Masconstraintmaker *Make ) { -         +         //Distance above 50 (can not write the reference system) custom to write-----parentheses inside A         //make: The equivalent of the view you want to lay out at         //Equalto (refer to view object), if the reference view is Self.view. You can not set properties of the reference view -         //offset (distance value) -Make.top.equalTo (Self.view). Offset ( -); -         //distance to the left -Make.left.equalTo (Self.view). Offset ( -); -         //from the right . inMake.right.equalTo (Self.view). Offset (- -); -         //from below toMake.bottom.equalTo (Self.view). Offset (- -); +      -          the     }]; *      $ #pragmaMark Lable1Panax Notoginseng      -UILabel *lable1 = [UILabelNew]; theLable1.backgroundcolor =[Uicolor Greencolor]; + [Self.view addsubview:lable1]; A     //layout The reference view first, or the constraint is easily lost the[Lable1 mas_makeconstraints:^ (Masconstraintmaker *Make ) { +         //layout Lable1 and lable Align left -         //Equalto (custom view), you need to set the view properties $         //if the value is 0, you can not write offset () $ Make.leading.equalTo (lable.mas_leading); -          -          //layout Lable1 and lable Align Right the Make.trailing.equalTo (lable.mas_trailing); -         //Top Distance Lable1WuyiMake.top.equalTo (Lable.mas_bottom). Offset ( -); the  -         //Height WuMake.height.mas_equalTo ( -); -     }]; About #pragmaMark Lable2 $      -UILabel *lable2 = [UILabelNew]; -Lable2.backgroundcolor =[Uicolor Cyancolor]; - [Self.view addsubview:lable2]; A     //structure (inner margin) +     //set the padding of the distance reference view (top left and bottom right) theUiedgeinsets pading = Uiedgeinsetsmake ( -, -, -, -); -      $[Lable2 mas_makeconstraints:^ (Masconstraintmaker *Make ) { the      the //Make.leading.equalTo (Self.view). offset (+); the //Make.trailing.equalTo (Self.view). Offset ( -100); the //Make.bottom.equalTo (Self.view). Offset ( -100); - //Make.top.equalTo (Self.view). offset (+); in         //sets the boundary value of the constraint view's boundary distance Self.view the Make.edges.equalTo (Self.view). insets (pading); the          About      the     }]; the      the #pragmaMark Lable3 +      -UILabel *lable3 = [UILabelNew]; theLable3.backgroundcolor =[Uicolor Orangecolor];Bayi [Self.view Addsubview:lable3]; the[Lable3 mas_makeconstraints:^ (Masconstraintmaker *Make ) { the         -         //Set Center point consistency - Make.center.equalTo (lable2); the         //Set Size the         //make.width = lable2.width-40 the         //make.height = labele2.height-60 theMake.size.equalTo (Lable2). Sizeoffset (Cgsizemake (- +, - -)); -     }]; the}

Masonry self-adapting screen

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.