Suche…
Erstellen Sie eine horizontale Stapelansicht programmgesteuert
Swift 3
let stackView = UIStackView()
stackView.axis = .horizontal
stackView.alignment = .fill // .leading .firstBaseline .center .trailing .lastBaseline
stackView.distribution = .fill // .fillEqually .fillProportionally .equalSpacing .equalCentering
let label = UILabel()
label.text = "Text"
stackView.addArrangedSubview(label)
// for horizontal stack view, you might want to add width constraint to label or whatever view you're adding.
Schnell
let stackView = UIStackView()
stackView.axis = .Horizontal
stackView.alignment = .Fill // .Leading .FirstBaseline .Center .Trailing .LastBaseline
stackView.distribution = .Fill // .FillEqually .FillProportionally .EqualSpacing .EqualCentering
let label = UILabel(frame: CGRectZero)
label.text = "Label"
stackView.addArrangedSubview(label)
// for horizontal stack view, you might want to add width constraint to label or whatever view you're adding.
Ziel c
UIStackView *stackView = [[UIStackView alloc] init];
stackView.axis = UILayoutConstraintAxisHorizontal;
stackView.alignment = UIStackViewAlignmentFill; //UIStackViewAlignmentLeading, UIStackViewAlignmentFirstBaseline, UIStackViewAlignmentCenter, UIStackViewAlignmentTrailing, UIStackViewAlignmentLastBaseline
stackView.distribution = UIStackViewDistributionFill; //UIStackViewDistributionFillEqually, UIStackViewDistributionFillProportionally, UIStackViewDistributionEqualSpacing, UIStackViewDistributionEqualCentering
UILabel *label = [[UILabel alloc] initWithFrame:CGRectZero];
label.text = @"Label";
[stackView addArrangedSubview:label];
//For horizontal stack view, you might want to add a width constraint to your label or whatever view you are adding.
Erstellen Sie eine vertikale Stapelansicht programmgesteuert
Schnell
let stackView = UIStackView()
stackView.axis = .Vertical
stackView.alignment = .Fill // .Leading .FirstBaseline .Center .Trailing .LastBaseline
stackView.distribution = .Fill // .FillEqually .FillProportionally .EqualSpacing .EqualCentering
let label = UILabel(frame: CGRectZero)
label.text = "Label"
stackView.addArrangedSubview(label)
// for vertical stack view, you might want to add height constraint to label or whatever view you're adding.
Ziel c
UIStackView *stackView = [[UIStackView alloc] init];
stackView.axis = UILayoutConstraintAxisVertical;
stackView.alignment = UIStackViewAlignmentFill; //UIStackViewAlignmentLeading, UIStackViewAlignmentFirstBaseline, UIStackViewAlignmentCenter, UIStackViewAlignmentTrailing, UIStackViewAlignmentLastBaseline
stackView.distribution = UIStackViewDistributionFill; //UIStackViewDistributionFillEqually, UIStackViewDistributionFillProportionally, UIStackViewDistributionEqualSpacing, UIStackViewDistributionEqualCentering
UILabel *label = [[UILabel alloc] initWithFrame:CGRectZero];
label.text = @"Label";
[stackView addArrangedSubview:label];
//For vertical stack view, you might want to add a height constraint to your label or whatever view you are adding.
Zentriertasten mit UIStackview
Schritt 1: - Nehmen Sie die 4 Taste in Ihrem Storyboard. Button1, Button2, Button 3, Button4
Schritt 2: - Allen Schaltflächen feste Höhe und Breite zuweisen.
Schritt 3: - Alle 2 - 2 Tastenpaare in 2-Stack-Ansicht.
Schritt 4: - Legen Sie die UIStackview-Eigenschaft für beide fest.
Distribution -> Fill Equally
Spacing -> 5 (as per your requirement)
Schritt 5: - Fügen Sie beide Stackview in einem Stackview hinzu
Schritt 6: - Distribution = Fill equally Spacing =5
einstellen Distribution = Fill equally Spacing =5
Gleiche Fläche Distribution = Fill equally Spacing =5
in der Hauptstapelansicht
Schritt 7: - Setzen Sie nun Constrain auf main stackview
center Horizontally in container
center vertically in container
and select Update Frame.
Schritt 8: - Es ist Zeit für die Ausgabe für alle Geräte.
Modified text is an extract of the original Stack Overflow Documentation
Lizenziert unter CC BY-SA 3.0
Nicht angeschlossen an Stack Overflow