खोज…
प्रोग्रामेटिक रूप से एक क्षैतिज स्टैक दृश्य बनाएं
स्विफ्ट 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.
तीव्र
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.
उद्देश्य सी
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.
प्रोग्रामेटिक रूप से वर्टिकल स्टैक दृश्य बनाएं
तीव्र
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.
उद्देश्य सी
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.
UIStackview के साथ केंद्र बटन
चरण 1: - अपने स्टोरीबोर्ड में 4 बटन लें। बटन 1, बटन 2, बटन 3, बटन 4
चरण 2: - सभी बटन को निश्चित ऊंचाई और चौड़ाई दें।
चरण 3: - 2 स्टैकव्यू में सभी 2 - 2 बटन की जोड़ी।
चरण 4: - दोनों के लिए सेट करें UIStackview गुण।
Distribution -> Fill Equally
Spacing -> 5 (as per your requirement)
चरण 5: - एक Stackview में दोनों Stackview जोड़ें
चरण 6: - Distribution = Fill equally Spacing =5
सेट करें Distribution = Fill equally Spacing =5
मुख्य स्टैकव्यू में Distribution = Fill equally Spacing =5
(अपनी आवश्यकता के अनुसार सेट करें)
चरण 7: - अब कांस्ट्रेन को मुख्य स्टैकव्यू पर सेट करें
center Horizontally in container
center vertically in container
and select Update Frame.
चरण 8: - यह सभी डिवाइस के आउटपुट के लिए समय है।
Modified text is an extract of the original Stack Overflow Documentation
के तहत लाइसेंस प्राप्त है CC BY-SA 3.0
से संबद्ध नहीं है Stack Overflow