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

How to remove bottom padding of UILabel with attributedText inside UIStackView

I want to remove the bottom padding of a UILabel with attributedText inside a UIStackview. I found this solution How to remove the extra padding below an one line UILabel. This works with normal text but not with attributed text. let textLabel…
Matthias
  • 1,150
  • 20
  • 38
2
votes
3 answers

How do I ensure UILabel only takes the space it requires, without extra padding?

I have a peculiar issue when dealing with my label in Vertical, then horizontal stack view. The horizontal stack view is supposed to be of a dynamic height based on the label's contents. I've tried other solutions mentioned before, such as embedding…
Karim
  • 271
  • 2
  • 11
2
votes
1 answer

Iterate StackView, Swift

I have a custom cell composed by 3 StackView. Each one of them has a title, a description and an image, horizontally. I have to fill this cell with an Array, it could be made of max 3 elements, but it could have 2 or 1. So in my viewModel I'm…
ConteOlaf
  • 75
  • 2
  • 8
2
votes
0 answers

Creating a dynamic horizontal view with static-width child views

I've spent days trying to get this to work, but nothing seems to be going right. What I'm trying to do is basically recreate this view (NOT the functionality): However, I have a few extra requirements that I've set for myself. When the user moves…
user2343632
  • 167
  • 7
2
votes
1 answer

Center views horizontally in iOS stack view

I'm trying to achieve the following layout (views centered horizontally): So I set up a stack view like so: let quickPromptsView: UIStackView = { let sv = UIStackView() sv.axis = .horizontal sv.alignment = .center sv.distribution =…
Cesare
  • 9,139
  • 16
  • 78
  • 130
2
votes
1 answer

Use Autolayout for Child View Controllers

I am having trouble with auto layout again... Here's what I want to get in the end: I am doing everything in code with a Parent View Controller and Child View Controllers top, center and bottom. In the end, I want to be able to set the height of…
appfrosch
  • 1,146
  • 13
  • 36
2
votes
1 answer

addArrangedSubview is overlapping views

My problem - when I add arranged subviews to a stackview programmatically, they just pile up in the upper right-hand corner as shown below. Why aren't they stacking up? I've tried many, many things including using views that have an intrinsic size. …
squarehippo10
  • 1,855
  • 1
  • 15
  • 45
2
votes
1 answer

Why do nested UIStackViews with UILabels require Y position and height constraints?

I am trying to sort out a problem we have in a UITableViewCell. There are nested UIStackViews with subviews like UILabel having an intrinsic content size. I created this example for simplified explanation of my problem: Results in these interface…
p13n
  • 859
  • 8
  • 31
2
votes
2 answers

How to scroll UIStackView horizontally when VoiceOver swipe?

I have a horizontal UIStackView with several buttons inside. The number of button is not constant and the length of stack view may exceed screen width. I use the structure UIScrollView - UIView - UIStackView to right align when the length is…
ArgenBarbie
  • 571
  • 1
  • 4
  • 10
2
votes
1 answer

Item in UIStackView not appearing

https://spin.atomicobject.com/2017/02/20/uistackview-stacking-child-views/ I am following along this tutorial to get views stacking on top of each other and using their intrinsic content size. However when I apply the Content Hugging Priority to the…
KvnH
  • 496
  • 1
  • 9
  • 30
2
votes
1 answer

Why do UILabel inside UIStackView lose its height when reusing occurs?

When cells are reused, the UILabels inside the UIStackView begin to lose their size. What it may be related to. For the table, cell heights are set in UITableView.automaticDimension. I do not understand how this is related to re-use, because I use…
2
votes
3 answers

Horizontal StackView issue for multiline label and fixed size icon image

I want to show a an icon image which is fixed size of 20px X 20px ,It is showing good when a label is only one line but not showing accurately when label became in two lines.Screenshot is attached.
Gurpreet Singh
  • 803
  • 9
  • 16
2
votes
1 answer

UIStackView different show hide animation between ios versions

UIStackView hide show animation is very different between ios versions. Here is a basic setup. I have a UIStackView with three arranged subviews inside it. And UIScrollView contains UIStcakView. I use auto layout. The stack view code is this: let…
mustafa
  • 15,254
  • 10
  • 48
  • 57
2
votes
1 answer

Empty UIStackView causes ambiguous hieght/position

I have two views, one UIView and one UIStackView let mainView = UIView() mainView.translatesAutoresizingMaskIntoConstraints = false let stackView = UIStackView() stackView.axis = .vertical stackView.translatesAutoresizingMaskIntoConstraints =…
sch
  • 1,368
  • 3
  • 19
  • 35
2
votes
1 answer

How to add corner radius to UIStackView and mask subviews

I use a simple subclass for UIStackView to add background color for it: func backgroundColor(_ color: UIColor?) { backgroundView.backgroundColor = color } func cornerRadius(_ radius: CGFloat) { …
Tanya Marchuk
  • 167
  • 11