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