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

2019-10-30  本文已影响0人  guoguojianshu
   /*
     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);
    }];
上一篇 下一篇

猜你喜欢

热点阅读