首页 > 代码库 > UIStackView使用 (堆视图)

UIStackView使用 (堆视图)

一基本使用

  1创建多个子控件

   

for (int i = 0; i < 3; i++)
    {
        UIButton *imgBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        imgBtn.backgroundColor = [UIColor redColor];
        [imgBtn setNormalImageWithName:@""];
        [imgBtns addObject:imgBtn];
    }

   2创建堆控件

//创建堆控件
    UIStackView *stackView = [[UIStackView alloc] initWithArrangedSubviews:imgBtns];
    [self.view addSubview:stackView];
    [stackView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(titleLabel.mas_bottom).offset(10);
        make.left.mas_equalTo(60);
        make.right.mas_equalTo(-60);
        make.height.mas_equalTo(80);
    }];

 

  3设置属性

stackView.axis = UILayoutConstraintAxisHorizontal;
stackView.distribution = UIStackViewDistributionFillEqually;
stackView.spacing = 35;

 

  

UIStackView使用 (堆视图)