Questions tagged [uistackview]

The UIStackView class provides a streamlined interface for laying out a collection of views in either a column or a row. Stack views let you leverage the power of Auto Layout, creating user interfaces that can dynamically adapt to the device’s orientation, screen size, and any changes in the available space.

The UIStackView class provides a streamlined interface for laying out a collection of views in either a column or a row. Stack views let you leverage the power of Auto Layout, creating user interfaces that can dynamically adapt to the device’s orientation, screen size, and any changes in the available space. The stack view manages the layout of all the views in its arrangedSubviews property. These views are arranged along the stack view’s axis, based on their order in the arrangedSubviews array. The exact layout varies depending on the stack view’s axis, distribution, alignment, spacing, and other properties.

enter image description here

To use a stack view, open the Storyboard you wish to edit. Drag either a Horizontal Stack View or a Vertical Stack View out from the Object library, and position the stack view where desired. Next, drag out the stack’s content, dropping the view or control into the stack. You can continue to add views and controls to your stack, as needed. Interface Builder resizes the stack based on its content. You can also adjust the appearance of the stack’s content by modifying the Stack View’s properties in the Attributes inspector.

1429 questions
4
votes
1 answer

Should I invalidate intrinsic content size for the whole hierarchy?

Suppose I have the following view hierarchy with Auto Layout enabled: UIStackView |__ OuterCustomView (overridden intrinsic content size) |__ UILabel |__ InnerCustomView (overridden intrinsic content size) |__UILabel …
wh1t3cat1k
  • 3,146
  • 6
  • 32
  • 38
4
votes
4 answers

Labels inside of horizontal stack view are of equal width?

I have a stack view with these properties: Axis: Vertical Alignment: Fill Distribution: Fill I add other horizontal stack views to that vertical one with the below properties: Axis: Horizontal Alignment: FirstBaseline Distribution: Fill Each one of…
user9168699
  • 83
  • 1
  • 2
  • 4
4
votes
3 answers

iOS AutoLayout constraint `lessThanOrEqualToConstant` doesn't work

I have an issue with auto layout constraints for UIView inside the UIStackView. My goal is to create a view: private static func makeSpace(with value: CGFloat) -> UIView { let view = UIView() view.translatesAutoresizingMaskIntoConstraints =…
Daumantas Versockas
  • 797
  • 1
  • 10
  • 29
4
votes
0 answers

Adding views to Stackview, but the subviews of the stackview overlap with each other

I need to adding views to stackview by using "for in" loops. However, the views in the stackview are overlap with each other. addplantoPlanArray samply init a view and add it to the PlanArray, then using "for in" loop to add each view in that Array…
Gang Wei
  • 63
  • 1
  • 6
4
votes
1 answer

UIStackView hiding views and unsatisfiable layout on rotation

I have a view controller in which I would like to hide certain subviews, labels, etc., depending on what the trait collection is. For example, I have labels on the side I want to hide when compact horizontally, and labels on the top and bottom I…
John Stewart
  • 1,176
  • 1
  • 10
  • 22
4
votes
3 answers

When should we use UIStackView?

I am designing iOS Application since 2 years. I have designed 8-10 applications with using UIScrollView, UICollectionView and many more native views. But I have never used UIStackView. I have gone through many documents of UIStackView, but I am not…
Aman.Samghani
  • 2,151
  • 3
  • 12
  • 27
4
votes
1 answer

Method not fired in UICollectionView when added within a UIStackview

I have added a UICollectionVIew to a vertical Stack View. I connected both datasource and Delegate from storyboard and added the delegate/datasource from the code as well. However, the following method is not being called at all: internal func…
Illep
  • 16,375
  • 46
  • 171
  • 302
4
votes
2 answers

Xcode/Stackview, empty labels freaks out in stack view?

hopefully an easy one here. I have some labels and text fields. Between them, I want some empty labels, which will if needed to be error texts. But when I try to stack view it all, Xcode zooms out and nothing can be seen on the…
Jonas Larsen
  • 378
  • 4
  • 14
4
votes
2 answers

Multiline UILabel bottom gets cut off after scrolling, UITableViewCell -> UIStackView -> UILabel

The layers: UITableViewCell -> UIStackView -> UILabel, table height is set to automatic dimension. Run it, everything is fine After some scrolling, the bottom of the multiline label gets cut off UILabel and stack view settings: lay out…
jc127
  • 343
  • 2
  • 13
4
votes
1 answer

Making a UITextView work inside a UIStackView

I'm trying to add some UITextViews to a UIStackView and the text views aren't showing up. I've researched this issue and the #1 answer I found was to make UITextViews.enableScrolling set to false. However, when I do that, the text view becomes very…
Sean Zlatnik
  • 187
  • 2
  • 12
4
votes
1 answer

Programmatically adding views to a UIStackView

I am attempting to add two dynamic UILabels to a UIStackLabel. The goal is center the two labels horizontally in the middle of the view. The two UILabels are: var nameLabel: UILabel! var ageLabel: UILabel! And the UIStackView is: var…
daspianist
  • 5,336
  • 8
  • 50
  • 94
4
votes
1 answer

Fixed Height Constraints for UIStackview's subviews

I have a UIScrollView that has a UIStackView subview, call it stack. I want to have a dynamic number of subviews in stack, but these subviews will have different heights. How can I achieve this? Please note that I'm trying to shy away from…
7ball
  • 2,183
  • 4
  • 26
  • 61
4
votes
3 answers

Buttons not maintaining size constraints in StackView

I am working on the Implementing A Custom Control iOS tutorial (I would link it but I'm not allowed to use more than two links). I am at the point where I have 5 buttons generate within a StackView. I implemented these constraints for each…
wazawoo
  • 545
  • 5
  • 18
4
votes
0 answers

Buttons not clickable when inside a StackView inside a StackView

I have a UIView Subclass which presents three buttons arranged with two above one. I use a StackView to arrange the top two buttons, and the bottom arranged view is just a single button. The problem is that the button added as an arrangedSubview…
Alex Bollbach
  • 4,370
  • 9
  • 32
  • 80
4
votes
1 answer

Resizing UIStackView after changing UILabel number of lines

My iOS app has a tableview with one UITableViewCell with the following layout (1 stackview containing 2 labels and 1 button) When the user taps the button the number of lines of the central label goes from 0 to 2 and will look like this: Now there…
Claus
  • 5,662
  • 10
  • 77
  • 118