迅速
let stackView = UIStackView() stackView.axis = .Vertical stackView.alignment = .Fill // .Leading .FirstBaseline .Center .Trailing .LastBaseline stackView.distribution = .Fill // .FillEqually .Fill按比例.EqualSpacing .EqualCentering let label = UILabel(frame: CGRectZero) label.text = "Label" stackView.addArrangedSubview(label) // 对于垂直堆栈视图,您可能想在标签或要添加的任何视图中添加高度限制。
目标C
UIStackView *stackView = [[UIStackView alloc] init]; stackView.axis = UILayoutConstraintAxisVertical; stackView.alignment = UIStackViewAlignmentFill; //UIStackViewAlignmentLeading,UIStackViewAlignmentFirstBaseline,UIStackViewAlignmentCenter,UIStackViewAlignmentTrailing,UIStackViewAlignmentLastBaseline stackView.distribution = UIStackViewDistributionFill; //UIStackViewDistributionFillEqually,UIStackViewDistributionFillEqually,UIStackViewDistributionEqualSpacing,UIStackViewDistributionEqualCentering UILabel *label = [[UILabel alloc] initWithFrame:CGRectZero]; label.text = @"Label"; [stackView addArrangedSubview:label]; //对于垂直堆栈视图,您可能要向标签或要添加的任何视图添加高度限制。