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
12
votes
2 answers

How to set height of containers in stack view?

I'd like to ask you if it's possible to set height in percentage of each container placed in vertical stack view? I want to have 3 containers in stack view. First should take 40% of screen size, second 20% and third 40%. Thank you
Lachtan
  • 4,803
  • 6
  • 28
  • 34
12
votes
1 answer

Padding or margin for UILabels in UIStackView

I want to add margins or paddings on the right of some nested UILabels like shown here: Using trailing spaces on the labels seems wrong and old-school somehow. Any way to make that more elegant on interface builder?
hanneskl
  • 193
  • 1
  • 2
  • 6
11
votes
3 answers

Flipping the positions of items in a UIStackView

I have a UIStackView, created in Interface Builder that contains two views. Now I'm trying to programatically change the order of these views (exchange their positions, so to speak). Is there an easy fix for this that DOES NOT use Interface Builder…
ilikecode
  • 391
  • 3
  • 14
11
votes
2 answers

Y Constraint missing in Vertical StackView

I have a UITableViewCell that has an embedded UIStackView in it. Everything works and looks fine on the phone and iPad. However, I get a lot of weird errors in the StoryBoard and I don't know if I can ignore them or not. Typically, I hate ignoring…
Justin Pfenning
  • 433
  • 1
  • 5
  • 18
11
votes
2 answers

UIStackView miscalculating UIImageView height

I have a UIStackView contained inside of a UICollectionViewCell to represent a post on a social network (similar style to Instagram's cells). The UIStackView contains an author header (custom UIView), a UIImageView for the content image, a UILabel…
Kiran Panesar
  • 3,094
  • 2
  • 22
  • 28
11
votes
1 answer

Using UIStackView to center single view

I've been trying to setup a simple container view in IB using UIStackView. I want this container to center its only arranged subview and respect the intrinsic content size of the subview. Unfortunately for all possible configuration of alignment and…
Robert Wijas
  • 693
  • 7
  • 14
10
votes
4 answers

How to create the equivalent of a SwiftUI stack view spacer programmatically

I'm working on trying to recreate the first SwiftUI Tutorial in code without using SwiftUI. In the example, it mentions using a Spacer "to direct the layout to use the full width of the device": VStack { Text("Turtle Rock") HStack { …
Andrew
  • 227,796
  • 193
  • 515
  • 708
10
votes
1 answer

UIStackView content hugging is not working as expected in UITableViewCell

I have two vertical StackView nested in horizontal StackView. For the first one: titlesView.axis = .vertical titlesView.distribution = .fill titlesView.alignment = .leading And the second one: checkView.axis = .vertical checkView.distribution =…
Mehrdad Faraji
  • 3,744
  • 3
  • 25
  • 38
10
votes
4 answers

How to center both vertical and horizontal inside a UIStackView

I have a simple UIImageView with 50x50 size. If I had a UIView of size 100x100 and I wanted to center the image inside of it, all I have to do is set these But how do I do the same with a UIStackView of size 100x100? EDIT i think i should have been…
Just a coder
  • 15,480
  • 16
  • 85
  • 138
10
votes
1 answer

Determine UIStackView contentsize

Is there a simple way to get the total content size of a UIStackView? To give an example: I programmatically create an array of UIViews... var numberOfSubViews = 5 let subViews: [UIView] = { var array: [UIView] = [] for _ in 0..
HNK
  • 332
  • 3
  • 12
10
votes
3 answers

Undeleteable constraints added by InterfaceBuilder

I'm using Xcode 8 building for iOS 9 and using auto layout. Occasionally when I install a constraint in Interface Builder there's an immediate conflict. When I click the red disclosure and look at the conflicting constraints I'll see the one I just…
David U
  • 943
  • 1
  • 8
  • 22
10
votes
5 answers

How can I make self sizing UITableViewCell with a UIStackView inside it

I can't achieve a self sizing UITableViewCell with a UIStackView inside it. For the UITableViewCell I'm doing something like this: On code I'm doing this: override func viewDidLoad() { super.viewDidLoad() self.tableView.estimatedRowHeight =…
pableiros
  • 14,932
  • 12
  • 99
  • 105
10
votes
1 answer

Programmatically add subviews to a UIStackView

I'm trying to implement a table view cell that displays a series of icons that represent home amenities (e.g. towels, wifi, laundry, etc.). The cell could potentially display a large number of amenities (depending on how many the home has), so I'll…
kcstricks
  • 1,489
  • 3
  • 17
  • 32
10
votes
2 answers

Direction of animation when un-hiding a UIStackView element

When I take a UIView that is an element of a vertical stack view and change that element's "hidden" property from true to false, the change is automatically animated, and the element moves downward as it becomes visible. I want it to move upward…
9
votes
3 answers

How do I align the bottoms of two labels in a horizontal UIStackView?

I have two labels in a horizontal UIStackView. Label 1 is a large font (the alarm time), Label 2 is a small font (AM/PM indicator) and I want to align the bottoms of each label. I have the alignment of the stack view set to Bottom, but it seems…
Austin Berenyi
  • 1,013
  • 2
  • 13
  • 25