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
3
votes
1 answer

Xcode expects UILabel in stack view to have greater height than it is

I am trying place two identically sized sets of a UILabel directly above a UITextField on a UIView. I figured that this would be an excellent use of stack views. Here is a screenshot of my elements However, for some reason, Xcode seems to expect…
ixchi
  • 2,349
  • 2
  • 26
  • 23
3
votes
2 answers

UIStackView : Change UIStackView image width using storyboard

The issue : Image take most of the stack and text shrinks I tried to change content hugging priority but no changes ! How to do it in UIStackview using storyboard? What I want the cell to look like Eventbright event Cell? What I got is an image…
user3662992
  • 688
  • 1
  • 6
  • 16
2
votes
2 answers

Access and update label.text or other UILabel properties inside a stackview programatically in Swift

I created a stackview with labels programatically in Swift. However, I was trying to find out how i can update the labels programmatically? (I did not use storyboard or IBOutlets) let LabelStack: UIStackView = { let label1: UILabel…
Daniel C
  • 113
  • 1
  • 8
2
votes
2 answers

UIView hidden is not getting set

I have a UIView subclass that is added as an arranged subview of a UIStackView. Depending on the data in the model, I want to either hide or show the arranged subview (called myView), but the problem is that when I go to hide it, even if I set…
ashipma
  • 423
  • 5
  • 15
2
votes
1 answer

How to dynamically resize text view inside a stack view

I'm trying to display a dynamically sized UITextView inside a stack view, but the text view is not adjusting to the size of the content. First I have the arranged subview: class InfoView: UIView { private var title: String! private var…
Kevvv
  • 3,655
  • 10
  • 44
  • 90
2
votes
1 answer

How to pin stackView to a view in such a way that it grows from bottom to top

I have a stackView inside a scrollView and I would like to pin the stackView such that it starts from the bottom and grows going up as more views are added to it. Image showing current behaviour showing the stackView pinned to the top of the view…
kaddie
  • 233
  • 1
  • 5
  • 27
2
votes
1 answer

iOS pinch gesture to control stack view spacing

I have a calendar based app I want the user to be able to pinch to zoom in and out of the calendar. This is my code: let p = UIPinchGestureRecognizer(target: self, action: #selector(pinch)) view.addGestureRecognizer(p) @objc func…
אורי orihpt
  • 2,358
  • 2
  • 16
  • 41
2
votes
1 answer

Fitting UIStackView in UIScrollView programmatically

I added a stackView to a scrollView. I set the width, X, and Y constraints of the scrollView same as main view, with a fixed height of 50. For the stack constraints, I did the same thing but relative to the scrollView instead of the view. My issue…
2
votes
3 answers

Swift UIStackView spacing with nested stack view(s)

Following along with Apple's guide here (I've done it programmatically instead), I've created 3 horizontal stack views nested inside a vertical stack view. To make the text fields align, they're each in a horizontal stack view as well. Is there a…
h.and.h
  • 690
  • 1
  • 8
  • 26
2
votes
2 answers

Content hugging priority not working with custom view and label in UIStackView

I am having trouble getting content hugging working on a custom view. I have the following code: pillView.setContentHuggingPriority(.required, for: .horizontal) pillView.setContentCompressionResistancePriority(.required, for:…
Kex
  • 8,023
  • 9
  • 56
  • 129
2
votes
1 answer

Swift: UIStackView height is always 0 despite adding elements

I have this stack view, it contains one ImageView: If I print its height, I always get 0: print("movieDetailsStackView!.bounds.height: ",movieDetailsStackView!.bounds.height ) // 0 print("movieDetailsStackView!.frame.height:…
AG_HIHI
  • 1,705
  • 5
  • 27
  • 69
2
votes
1 answer

UIStackView horizontal compression/hugging issue. Need final item to stretch to fill the remaining width, but NOT compress the other items if large

I have a horizontal stack view in a UICollectionViewCell. There a four items in the stack view, the first three are specialized UILabels (seen as "loose", "$?", and a score of 75), I never want to be compressed. The final item is a specialized…
StainlessSteelRat
  • 364
  • 1
  • 2
  • 16
2
votes
4 answers

button stackView spacing not working -Swift - Programmatically

I'm adding a stackView in my viewcontroller in this way: addSubview(stackView) stackView.translatesAutoresizingMaskIntoConstraints = false stackView.anchor(top: nameLabel.bottomAnchor, leading: leadingAnchor, bottom: bottomAnchor, trailing:…
StackGU
  • 868
  • 9
  • 22
2
votes
1 answer

How to align top of UILabel to top of another UILabel?

I want to achieve following UI: This UI contains label (which is bold on top), stackview (inside blue rectangle), view (gray line) and two labels below of line. As you see, I have separate view inside stackview. Here is how its constraints are…
neo
  • 1,314
  • 2
  • 14
  • 34
2
votes
1 answer

UICollectionViewCell populate with wrong data

I have simple UICollectionViewCell that contains one product. My product have image(UIImageView), name(UILabel), description(UILabel), price(UILabel), rating(UIStackView) shown with 0 to 5 stars and buy button. I fetch my products from JSON and save…