Stack View能够将它所含的View以各种方式沿其轴向进行分布,同时也可以将View沿某个方向等距分布
例://实现子控件等分
UIStackView *discountStackView = [[UIStackView alloc] init];
//设置轴向
discountStackView.axis = UILayoutConstraintAxisVertical;
//设置分布,等分分布
discountStackView.distribution = UIStackViewDistributionFillEqually;
//设置分布间距
discountStackView.spacing = 10;
//根据自定义模型数据的个数遍历创建视图
for(SUDiscoModel *dm in _shopDataModel.discoDataModel)
{
SUInforView *inf = [[SUInforView alloc] init];
inf.discData = dm;
[discountStackView addArrangedSubview:inf];
}
[contentView addSubview:discountStackView];
//约束
[discountStackView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.offset(10);
make.right.offset(-10);
make.top.equalTo(discountLabel.mas_bottom).offset(10);
make.height.offset(_shopDataModel.discoDataModel.count*30);
}];
效果:
例://实现子控件等分
UIStackView *discountStackView = [[UIStackView alloc] init];
//设置轴向
discountStackView.axis = UILayoutConstraintAxisVertical;
//设置分布,等分分布
discountStackView.distribution = UIStackViewDistributionFillEqually;
//设置分布间距
discountStackView.spacing = 10;
//根据自定义模型数据的个数遍历创建视图
for(SUDiscoModel *dm in _shopDataModel.discoDataModel)
{
SUInforView *inf = [[SUInforView alloc] init];
inf.discData = dm;
[discountStackView addArrangedSubview:inf];
}
[contentView addSubview:discountStackView];
//约束
[discountStackView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.offset(10);
make.right.offset(-10);
make.top.equalTo(discountLabel.mas_bottom).offset(10);
make.height.offset(_shopDataModel.discoDataModel.count*30);
}];
效果: