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

Why UIStackView resize arranged subviews?

Why UIStackView resize subviews? I think its work when I set distribution like .fill. But .equalSpacing does not imply such behavior. I'm right? let stackView = UIStackView() stackView.alignment = .firstBaseline stackView.axis = .vertical …
2
votes
2 answers

Increase area of UIButton in UIStackView

I have couple of UIButtons embedded in UIStackView. I understand UIStackView takes only the intrinsic size of UIButton when laying it out. But I want to increase height/width of UIButton when inside UIStackView. Without UIStackView, I can easily…
Deepak Sharma
  • 5,577
  • 7
  • 55
  • 131
2
votes
3 answers

StackView Not Aligning To The Left Programmatically

My StackView that I am making programmatically is looking like this: Two Subviews: Three Subviews: Four Subviews: This is my code: cameraButton.setImage(UIImage(named: "blueCamera"), for: .normal) cameraButton.addTarget(self, action:…
Cal
  • 422
  • 6
  • 20
2
votes
1 answer

UIStackView with "wrap content" width

Problem: Create horizontal UIStackView with 2 elements Item width with "Short text 2" should be "wrap content". Item with "Long text 1" should fill all free space. Please help to understand, how it can be created in code (Swift language)?
Natali
  • 2,934
  • 4
  • 39
  • 53
2
votes
0 answers

Inconsistent UIStackview isHidden animation

I have the following animation and I can't seem to figure out why it is not working consistently. The stack view is a series of UILabel subviews where I want to animate: hiding all of the labels without text and showing all that do. I have tried…
Elliot KG
  • 51
  • 4
2
votes
1 answer

UITableView inside a UIStackView height constraint issue

Requirement: Our application has a pattern where many screens have a number of UILabels on the top and a single UITableView bellow them which, when present, is always the last element on the page and expands right to the bottom of the screen.…
nonstopcoding
  • 729
  • 11
  • 21
2
votes
2 answers

UIStackView dynamcially add 2 labels next to each other with no extra spacing

Im new to iOS development and Im a bit confused as to how to achieve this. I have 2 UILabels added to a UIStackView like so: let horizontalStackView1 = UIStackView(arrangedSubviews: [self.label1, self.label2]) and when I run the app it looks like…
David Kroukamp
  • 36,155
  • 13
  • 81
  • 138
2
votes
1 answer

UIStackView in UITableView cell causes jerking when scrolled

I have a UITableView cell with a stack view inside. When the cell is tapped the data source changes and the table view is reloaded. The stack view will now have more views inside and the cell is bigger. However sometimes when I scroll the table…
Kex
  • 8,023
  • 9
  • 56
  • 129
2
votes
1 answer

Horizontal Stackview left align items

I am creating a horizontal UIStackView and want to left align items in it. Here is my code: let nameLabel: UILabel = { let label=UILabel() label.text = "First Name:" label.textColor = UIColor.black label.font =…
Shivam Pokhriyal
  • 1,044
  • 11
  • 26
2
votes
2 answers

UIStackview not resizing when hiding the labels inside it

Hi I'm new to UIStackViews. So I have a vertical Stackview containing 8 Labels. However, the problem with my Stackview is that whenever I hide the Labels inside it, my stackview does not resize. The labels within the Red Rectangle are in my…
Valysar
  • 41
  • 2
  • 6
2
votes
2 answers

stackView in the center scrollView

I want stackView will be in the center scrollView. Items of stackView can be equals 2 items or 15 items. But the elements always should be in the center. For example, if we have only one element it locates in center screen. If we have 10 items and…
Yurii Petrov
  • 341
  • 2
  • 14
2
votes
4 answers

How to animate UIStackView hiding inside UITableViewCell properly?

I want to animate the subviews of the TableViewCell which is StackView. When I hide the StackView, the TableViewCell height not updating. After googling, I found that I should call tableView.beginUpdates and tableView.endUpdates to notify tableView…
Jefferson Setiawan
  • 536
  • 1
  • 5
  • 22
2
votes
1 answer

UIStackView width & height not changing following elements addition

Context I am trying to create UIStackView programatically, but it isn't showing at all. To test, I created 2 small UIViews that I add to the UIStackView. I tried Adding, constraints to the UIStackView Using layoutIfNeeded Using layoutSubviews But…
kagawish
  • 65
  • 2
  • 10
2
votes
1 answer

Programatically add multiple horizontally stack views inside vertical stack view

This is the layout I want to achieve Label1 UIView Label2 <- horizontally stack view Label1 UIView Label2 Label1 UIView Label2 Label1 UIView Label2 Label1 UIView Label2 Every horizontally stack view contains a label and view and another label.…
Adrian
  • 19,440
  • 34
  • 112
  • 219
2
votes
3 answers

How to place UIView on top of other UIView?

Right now I have a collectionView for which each cell contains a horizontal stackView. The stackView gets populated with a series of UIViews (rectangles), one for each day of a month - each cell corresponds to a month. I fill the stack views like…
BigBoy1337
  • 4,735
  • 16
  • 70
  • 138