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
8
votes
3 answers

UITextView added from code missing in UIStackView

I'm trying to add a UITextView to UIStackView programatically, but it doesn't appear on the screen. When I check in Debug View Hierarchy, it is in the view hierarchy and it has some constraints but doesn't show up in the outputted view. This is my…
dorsz
  • 905
  • 10
  • 20
8
votes
1 answer

UIStackView - drag to reorder arranged subviews?

I'm trying to get some advice on how to go about implementing the same sort of "drag to reorder" behavior found on a UITableView but on a UIStackView. So far this is what I'm thinking: Add a long press gesture recognizer to each of the…
Clay Ellis
  • 4,960
  • 2
  • 37
  • 45
8
votes
2 answers

UIStackView Form Layout

I'm creating a basic form with various fields. I'd like to use UIStackView to layout all the controls. How would I do the following so the controls are aligned correctly? Is the UIStackView the correct way to do this?
Mr Rogers
  • 6,091
  • 2
  • 32
  • 34
7
votes
2 answers

UIStackView on TitleView Spacing issue after iOS 16

I have an UIStackView set up on the title view of the navigation bar in my app. It simply shows the icon of the app to the left of the title. In iOS 15 and earlier, this displayed fine. Right now, however, it shows fine the first time you launch the…
7
votes
1 answer

Vertical layout issue with 2 UILabels inside a StackView

I have a title label as defined below: private lazy var titleLabel: UILabel = { let label = UILabel() label.numberOfLines = 2 label.setContentCompressionResistancePriority(.init(rawValue: 999), for: .vertical) return label }() private lazy var…
DesperateLearner
  • 1,115
  • 3
  • 19
  • 45
7
votes
1 answer

Create a Horizontal Stackview with 2 UiView Inside

What I Want: I want to place 2 Views side by side in a horizontal way. For this I am creating UIStackView programmatically. Look at the below snippet What I Have Done: let mStackView = UIStackView() mStackView.axis =…
A.s.ALI
  • 1,992
  • 3
  • 22
  • 54
7
votes
2 answers

UIStackView inside UIScrollView, grows until maximum height then scrolls

I'm looking to build a view which will grow as subviews are added to it. At first the height will be zero, then should grow as I add subviews until it reaches a maximum size, and then I want it to become scrollable. If I build this using a UIView…
Wernzy
  • 1,088
  • 8
  • 22
7
votes
1 answer

How to eliminate superfluous line breaks from NSAttributedString (converted from HTML) in iOS UILabel object?

I have some table view cells that need to display some simple html from our server. Am converting the html into an NSAttributedString so that it can be displayed in UILabel objects on the cells. But when the table view draws the cells the UILabel…
Alyoshak
  • 2,696
  • 10
  • 43
  • 70
7
votes
2 answers

Horizontal stackview label grow with a fixed height element

I have a horizontal stackview with a UIImageView (1:1 Aspect Rati, Height 32) and a label. Since it has a height the stackView cuts off my label on the right not letting me have more than one line. I want the Horizontal StackView grow in height as…
Godfather
  • 4,040
  • 6
  • 43
  • 70
7
votes
1 answer

Make one view bigger than others inside UIStackView()

I have a UIStackView which consist of 5 elements. I want the centered one bigger than others (like in below pic). How I create UIStackView() stackView.axis = UILayoutConstraintAxis.horizontal stackView.distribution =…
Emre Önder
  • 2,408
  • 2
  • 23
  • 73
7
votes
1 answer

How to programmatically determine the height of UIStackView after a subview has been hidden swift

I am using a UIStackView within a UIScrollView and I want to determine the height of the stack view so I can programmatically adjust the height of the scrollview to accomodate when subviews are hidden. I am using stackView.frame.height to…
Khoury
  • 411
  • 1
  • 4
  • 21
7
votes
1 answer

iOS: Can't change a width in a horizontal stackview

I'm starting with iOS app and creating a table view. In my table I have a cell like this. Now I need to center the horizontal stackview with stars vertically and horizontally. This stackview has fixed width and height. It have to look like…
Vitalii
  • 10,091
  • 18
  • 83
  • 151
7
votes
1 answer

Hiding view in stack view in iOS 10

When I hide a UIView inside UIStackview, on iOS 11 it nicely removes the gap and brings the adjacent UIViews closer inside the UIStackView. However, on iOS 10 it will not move the adjacent views and just leave the gap for the hidden view. Is there a…
Kashif
  • 4,642
  • 7
  • 44
  • 97
7
votes
4 answers

Center views horizontally of different widths inside a UIStackView

I would like to setup a UIViewStack so that it will center the two views inside, even though they have different widths. Here is an example: Is it possible to achieve this type of configuration with UIStackView? I cannot seem to figure it out! Any…
Jason Silberman
  • 2,471
  • 6
  • 29
  • 47
7
votes
2 answers

Using a Stack View in a Scroll View and respecting Safe Area insets

I have a UIStackView inside a vertically scrolling UIScrollView with everything constrained using Auto Layout. The scroll view fills the superview, the stack view fills the scroll view, and various elements are added into the stack view. To allow…
Jordan H
  • 52,571
  • 37
  • 201
  • 351