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
1
vote
2 answers

UIStackView's subviews have intrinsic size, yet still ignore content hugging priorities

I'm trying to programmatically create a stack view with a fill distribution that allows me to choose which subview stretches to fill the extra space, but so far I can't seem to control which view is expanding. class ShelfVC: UIViewController { …
zakdances
  • 22,285
  • 32
  • 102
  • 173
1
vote
1 answer

Change width constraint of a Button in StackView Programmatically

I have a stackView which contains some UItextfields and one button. I have constrained it in ViewController viewDidLoad like this: let stackView = UIStackView() stackView.axis = .vertical stackView.spacing = 40 stackView.distribution =…
user13370778
1
vote
1 answer

Swift - StackView and Adding Constraints With Programmatically Added Views To Stack - Adjust Cell Hight After Load?

I'm trying to make a custom tableView cell that has a stackView from an array images. I used interface builder and added a horizontal stackView with: Center X Center Y Top +12 Bottom +12 I'm using a loop to add Arranged Subview and it works fine.…
StonedStudio
  • 507
  • 3
  • 20
1
vote
3 answers

Edit UIStackView programmatically

I'm currently trying to make a simple app which will have a small amount fo things to display depending on a users input. Currently, I have a stack view on my screen with a UIView inside of it. I am trying to make it so that once a button is pressed…
Fin M.
  • 139
  • 10
1
vote
2 answers

UITableView inside UIStackView layout margins

I currently have a UITableView embedded inside a UIStackView. I've currently set the StackView to have its own padding like so: stackView.layoutMargins = UIEdgeInsets(top: 0, left: 8, bottom: 0, right: 8) stackView.isLayoutMarginsRelativeArrangement…
Johnny
  • 62
  • 10
1
vote
1 answer

Bottom border is not added to view in StackView (ios)

I am trying to add UIView with the bottom border programatically to stack view.But border is not getting added to UIView(). Code to add UIView to stack view: func addOtpViews() { var otpLength=Int(otpLen as String)! …
Priya Kavi
  • 57
  • 6
1
vote
1 answer

Smooth animation in keyboardWillShow doesn't work with UITextView

Solution which worked for me After struggling for days I finally manage to find the fix for view animation issue. For me keyboardWillChangeFrameNotification worked. The solution is discussed in the following thread: Move textfield when keyboard…
Raymond
  • 1,108
  • 13
  • 32
1
vote
0 answers

How to align stack view vertically in center inside scroll view?

I've a stack view inside scroll view as shown in the image below. I want to align it vertically in center. It doesn't align vertically in center on iPhone 5S, it works fine on iPhone 11 Pro Max. I've seen this solution…
Raymond
  • 1,108
  • 13
  • 32
1
vote
1 answer

How can I make sure UIStackView notifies ALL it's descendants when it's arranged view's size changes?

I have a UIStackView with a 2 arranged child UIViews. The second UIView (a title view) has contentHugging set to high, and when it's contents changes, the first UIView (a content view) stretches it's size correctly. Everything looks fine. The…
zakdances
  • 22,285
  • 32
  • 102
  • 173
1
vote
2 answers

horizontal UIStackView centering

I'm trying to achieve the following with a horizontal UIStack View: An unknown number of checkboxes (up to 5) are to be displayed. I want them to be centered and equaly spaced like the following (2 separate images): If I had to have only one…
anon
1
vote
2 answers

displaying images in a stack view

Is it possible to display an image from the assets folder to a uistackview programmatically? If so, how would you go about doing it? I already know how to create a stack view filled with labels. fileprivate lazy var stack: UIStackView = { …
user13470903
1
vote
2 answers

How to remove mysterious top margin in UIStackView when `isLayoutMarginsRelativeArrangement=true`?

I'm creating a simple "toolbar" component with a horizontal axis UIStackView. It looks fine, except when I switch on isLayoutMarginsRelativeArrangement, a strange margin is added to the top above the items, making the height of the stack view…
zakdances
  • 22,285
  • 32
  • 102
  • 173
1
vote
3 answers

Is there a way to make a scrollview extend/shrink as needed in Swift?

I have a stackview (which the user can add/remove elements from) inside of a scrollview and I want the scrollview always adjust to have the same height as the stackview so that I don't have to add a bunch of unnecessary space if there's only a few…
dfisch
  • 11
  • 5
1
vote
2 answers

Altered column width in horizontal UIStackview

I have a 4 x 1 UILabel matrix in a horizontal stackview I would like columns 1 and 3 to be the same width BUT narrower than columns 2 and 4. I have tried .fillproportionally, and others. I understood that this was possible... however, a solution…
user3194306
  • 81
  • 1
  • 7
1
vote
2 answers

IOS| UILabel not visible in UIStack view

I am trying to build a vertical stack view with a UI label and multiple horizontal stack views, However, I only see the multiple horizontal stacks in the UI and not the UI label. Here is some code final class FinalView: UIView { let…
Nari
  • 333
  • 5
  • 13