美文网首页
使用masonry横向平铺,或者纵向,间隔相等,大小相同

使用masonry横向平铺,或者纵向,间隔相等,大小相同

作者: guoguojianshu | 来源:发表于2019-10-30 21:58 被阅读0次
    • API
       /*
         Parameters
         
         axisType
         which axis to distribute items along                     沿着那个轴进行布置(x轴或者y轴)
         fixedSpacing
         the spacing between each item                             每个项目之间的间距
         leadSpacing
         the spacing before the first item and the container       第一个项目和容器前的距离
         tailSpacing
         the spacing after the last item and the container         最后一个项目和容器后的距离
         
         
         - (void)mas_distributeViewsAlongAxis:(MASAxisType)axisType
         withFixedSpacing:(CGFloat)fixedSpacing
         leadSpacing:(CGFloat)leadSpacing
         tailSpacing:(CGFloat)tailSpacing;
         */
    
    • 使用
    -(void)CGQBZCreateUI{
        [self.contentView addSubview:self.CGQBZImageView];
        [self.contentView addSubview:self.CGQBZCategoryLabel];
        [self.contentView addSubview:self.CGQBZBigView];
        [self.contentView addSubview:self.CGQBZButton1];
        [self.contentView addSubview:self.CGQBZButton2];
        [self.contentView addSubview:self.CGQBZButton3];
        [self.contentView addSubview:self.CGQBZButton4];
        [self.contentView addSubview:self.CGQBZButton5];
        [self.contentView addSubview:self.CGQBZButton6];
        [self.contentView addSubview:self.CGQBZButton7];
        [self.contentView addSubview:self.CGQBZButton8];
        [self.contentView addSubview:self.CGQBZButton9];
    //把要设置的控件加入数组里面
        [self.CGQBZButtonArray addObject:self.CGQBZButton6];
        [self.CGQBZButtonArray addObject:self.CGQBZButton7];
        [self.CGQBZButtonArray addObject:self.CGQBZButton8];
        [self.CGQBZButtonArray addObject:self.CGQBZButton9];
    
        [self CGQBZMakeConstraint];
        
    }
    
    //间距为1,和屏幕左右都为0
      [self.CGQBZButtonArray mas_distributeViewsAlongAxis:MASAxisTypeHorizontal withFixedSpacing:1 leadSpacing:0 tailSpacing:0];
    //设size和frame
        [self.CGQBZButtonArray mas_updateConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(CGQBZWeakself.CGQBZButton1.mas_bottom).offset(1);
            make.width.mas_offset((CGQBZ_WIDTH-3)/4.0);
            make.height.mas_equalTo(CGQBZWeakself.CGQBZButton5.mas_height);
        }];
    

    相关文章

      网友评论

          本文标题:使用masonry横向平铺,或者纵向,间隔相等,大小相同

          本文链接:https://www.haomeiwen.com/subject/wyiavctx.html