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
35
votes
4 answers

How do you right align a horizontal UIStackView?

I've yet to find an answer for this anywhere and I'm not sure if it's possible, but I'm trying to right align a horizontal UIStackView, so that if subviews are hidden they move towards the right side not the left. Either programmatically (in Swift)…
35
votes
2 answers

How Can I have multiple widths and heights of subviews in a UIStackView

Say for example I want to add 3 buttons to a stack view. Button1 is 200 * 200 (1) Button2 is 150 * 150 (0.75) Button3 is 100 * 100 (0.5) How can I accomplish this in interface builder?
dubbeat
  • 7,706
  • 18
  • 70
  • 122
33
votes
1 answer

How To: Self-Sizing Custom-View from XIB with StackView View in iOS

I've recently started diving into iOS development with Swift again and am now looking into a custom UIControl. For layout and flexibility this custom view is built using a StackView. What I want to achieve ... ... is basically to simply have the…
martin
  • 591
  • 1
  • 8
  • 17
32
votes
4 answers

iOS/Swift: Dynamically size UIStackView when one of its items gets larger

I have two items in a vertical UIStackView: a UILabel and a UITableView. When a dynamic amount of UITableViewCells get added to the UITableView at runtime, the UIStackView does not get larger. Is there a general way to increase the size of the…
jshapy8
  • 1,983
  • 7
  • 30
  • 60
32
votes
1 answer

UIStackView - Distribute views evenly from the centre

I have a UIStackView,inside a UIScrollView to show dynamically added subviews horizontally arranged. Current solution will start displaying items from the left, I would like to start distributing items from the centre without changing the width and…
Ajith
  • 1,457
  • 3
  • 16
  • 29
32
votes
6 answers

How can I set the cornerRadius of a UIStackView?

I'm updating my app to use UIStackViews, now that most people should have updated to iOS 9. In the old version, I made a UIView consisting of two UITextFields and set its layer.cornerRadius property. In the new version, I created a UIStackView…
WallyAmerica
  • 423
  • 1
  • 5
  • 5
30
votes
1 answer

Dynamic UITableView row height using UIStackView?

Surprised this isn't working out of the box, as this seems to be an important use case for stack views. I have a UITableViewCell subclass which adds a UIStackView to the contentView. I'm adding labels to the stack view in…
memmons
  • 40,222
  • 21
  • 149
  • 183
29
votes
13 answers

UIStackView - layout constraint issues when hiding stack views

My app has 2 screens: TableViewVC (no stack views here) DetailVC (all the nested stack views here; please see link for picture: Nested StackViews Picture) -- Note, there are labels and images within these stack views. When you press a cell in…
JEL
  • 1,540
  • 4
  • 23
  • 51
27
votes
4 answers

Add tap gesture to UIStackView

Im attempting to add a UITapGesture to a UIStackView within a collectionView cell but each time I do my app crashes. (All IBOutlets are connected) This there something I'm doing wrong here? let fGuesture = UITapGestureRecognizer(target: self,…
Terrance
  • 275
  • 1
  • 3
  • 11
26
votes
2 answers

Fill Proportionally in UIStackView

I am using Storyboard to create a layout which consists of a UITableView and a UIView at the bottom. I am using UIStackView and playing them vertically. I want the UITableView to take 80% of the height and UIView (footer) to take 20%. I am using…
john doe
  • 9,220
  • 23
  • 91
  • 167
26
votes
4 answers

StackView isHidden attribute not updating as expected

I'm trying to update a UIStackView so that a field displays, should the value of a UITextField equal "Other". Here is my code: @IBOutlet var stackView: UIStackView! func updateView() { print("UPDATING") UIView.animate(withDuration: 0.25,…
Ben
  • 4,707
  • 5
  • 34
  • 55
26
votes
9 answers

Overlapping Views in UIStackView

I have an horizontal stack view that I added arranged sub views to it (7 cells). Each one of the cells in the stack has a circular badge that exceeds the view boundaries (negative constraint). When running, as you can see below, each cell is on top…
yossile
  • 768
  • 1
  • 6
  • 18
25
votes
5 answers

Negative spacer for UIBarButtonItem in navigation bar on iOS 11

In iOS 10 and below, there was a way to add a negative spacer to the buttons array in the navigation bar, like so: UIBarButtonItem *negativeSpacer = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil…
pckill
  • 3,709
  • 36
  • 48
25
votes
1 answer

Fix width of element in UIStackView

I create UIStackViews programmatically and add them to parent UIStackView, which is created in Storyboard. Child stack views are horizontal with 2 labels. I need to fix width of second UILabel and make the first UILabel fill the rest space. Now I…
Peter Tretyakov
  • 3,380
  • 6
  • 38
  • 54
22
votes
2 answers

How to size a UIStackView depending on its content?

I would like to have a similar behavior than the HTML tag, in the sense where the frame is sized according to its content. In my very context, I use an UIStackView as the content view of a UITableViewCell. As items in the cell are various…
Stéphane de Luca
  • 12,745
  • 9
  • 57
  • 95
1
2
3
95 96