AutoLayout three or nine palace lattice

Source: Internet
Author: User

Using masonry to complete the nine Gongge constraint setting, the effect:

First of all inside is a separate view, outside a container view

Itemview:
- (void) initsubviews {self.userinteractionenabled=YES; _imageview.userinteractionenabled=YES; _titlelabel.userinteractionenabled=YES;    @weakify (self); CGFloat width=_imageview.image.size.width; [_imageview mas_makeconstraints:^ (Masconstraintmaker *Make )        {@strongify (self); Make.top.mas_equalTo (self.mas_top);//Top of picture stickerMake.centerX.mas_equalTo (self);//Center PictureMake.width.mas_equalTo (width);//equals picture width    }]; [_titlelabel mas_makeconstraints:^ (Masconstraintmaker *Make )        {@strongify (self); Make.top.mas_equalTo (Self.imageView.mas_bottom). Offset ( -);//text compartment picture belowMake.centerX.mas_equalTo (Self.imageview);//CenterMake.bottom.mas_equalTo (Self.mas_bottom);//Text Bottom Sticker Superview    }];}

//Nine Gongge layout constraints core codeNsinteger Columns=3; CGFloat itemheight= the; CGFloat Gap= *; __block UIView*lastview =Nil;  for(inti =0; i < Self.shareList.count; i++) {Zsyinvitefriendsitemview*item =_sharelist[i];                [_shareview Addsubview:item]; [Item Mas_makeconstraints:^ (Masconstraintmaker *Make ) {                        if(Lastview) {make.width.equalTo (lastview.mas_width); } Else{make.size.mas_equalTo (Cgsizemake (Screen_width-Gap * (Columns +1))/Columns, itemheight)); }                        if(i% Columns = =0) {make.left.equalTo (Item.superview). Offset (GAP); }            Else{make.left.equalTo (lastview.mas_right). Offset (GAP); }            if(i% Columns = = (Columns-1) {make.right.equalTo (Item.superview). Offset (-Gap); }            inttop = (i/columns) * Gap + (I/columns *itemheight);                        Make.top.equalTo (Item.superview). offset (top); Lastview=item;    }]; }

AutoLayout three or nine palace lattice

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.