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

UIStackView, 2 labels: Change Axis based on size

I have two labels embedded inside a horizontal UIStackView. One of the labels might grow too large in size, therefore, one of them is truncated. Or, their sizes are being split in some proportion and they grow vertically. What I'm trying to achieve…
Richard Topchii
  • 7,075
  • 8
  • 48
  • 115
5
votes
3 answers

UIStackView setCustomSpacing at runtime

I have a horizontal UIStackView that, by default, looks as follows: The view with the heart is initially hidden and then shown at runtime. I would like to reduce the spacing between the heart view and the account name view. The following code does…
LinusGeffarth
  • 27,197
  • 29
  • 120
  • 174
5
votes
1 answer

Interface Builder is collapsing vertical stack view horizontally and back after each action

I am designing a view controller in Interface Builder and have a stack view. After any action (e.g. moving any object a tiny bit, or changing a constraint by 1px) the whole stack view collapses horizontally, messing up all the layout. Then, when I…
Can Poyrazoğlu
  • 33,241
  • 48
  • 191
  • 389
5
votes
3 answers

Dynamic height for a horizontal UIStackview

I have a horizontal StackView with distribution as "fill equally". It has 3 labels. I want one of the labels to have dynamic height. When I set the number of number of lines to 0 for that label, it ends up breaking the constraint the spacing…
AjinkyaSharma
  • 1,870
  • 1
  • 16
  • 26
5
votes
1 answer

Setting constant width on subview of UIStackView when axis is vertical

I have a UIScrollView that contains a UIStackView, and I add views to it and if the UIStackView needs more space than the screen has then it will scroll thanks to the UIScrollView. I am able to set constant heights on the views, but I also need to…
Alex
  • 5,671
  • 9
  • 41
  • 81
5
votes
1 answer

Stretch the last element in UIStackView

I have vertical UIStackView which has two horizontal UIStackViews, if bottom UIStackView has larger width than UIStackView on the top then UIStackView on the top will be stretched to the width of the bottom UIStackView. And now I have first element…
konstantin_doncov
  • 2,725
  • 4
  • 40
  • 100
5
votes
2 answers

UIStackView: add arranged views with the same width

I have UIStackView and want add to this view some arranged views... sometimes one, sometimes two, three... etc. UIStackView has full width. I want arranged views to have the same width with alignment left, so that they do not fill full width of…
birdy
  • 943
  • 13
  • 25
5
votes
3 answers

Swift UIView disappearing from Stack View

I have a label, an Image View, and a button in a vertical stack view. The alignment is set to fill, and the distribution to equal spacing with an offset of 10. On my storyboard, the label appears on top, the image in center, and the button at…
froggomad
  • 1,747
  • 2
  • 17
  • 40
5
votes
2 answers

What's the best approach to display a variable number of images within a TableViewCell in a xib file?

I am building an app about meetings where I want to show a preview of the VIP participants in each meeting cell. These participants are not clickable nor scrollable, the only purpose it's to quickly see them at a glance. The problem is that the view…
PMT
  • 1,082
  • 8
  • 18
5
votes
0 answers

multiline UILabel using AttributedText with lineSpacing is adding unwanted offset on iphone 6+ & 7+

I have a UILabel with attributed text that includes specific lineSpacing or lineHeightMultiple. let titleParagraphStyle = NSMutableParagraphStyle() //titleParagraphStyle.lineSpacing = lineSpacing titleParagraphStyle.lineHeightMultiple =…
nwales
  • 3,521
  • 2
  • 25
  • 47
5
votes
1 answer

dynamic height of UITableViewCell using UIStackView

For much to many hours I have been struggling to get dynamic row height calculation for UITableViewCells running. A StackView (pinned to the margins of the UITableViewCells contentView) should allow me to control the height of the cell by…
Jakob
  • 1,126
  • 3
  • 16
  • 38
5
votes
2 answers

Stack view arrangement of controls percentage wise in iOS swift

I am building an iOS app with a form and I am using stackviews. This is the example of what I want to achieve: The textbox and button are part of horizontal stack view. What I need is a way to allocate percentage-like width to them. For eg, textbox…
Rujoota Shah
  • 1,251
  • 16
  • 18
5
votes
1 answer

Fill UIStackView by Ratio?

I have a horizontal UIStackView with 2 views within it. I'd like to have the left view take up ~70% of the screen, and the right view take up the remaining 30%. I know that I can set the UIStackView alignment to Fill and the distribution to Fill…
Shadowman
  • 11,150
  • 19
  • 100
  • 198
5
votes
1 answer

Animate hidden property on UILabels in UIStackView causes different animations

UIStackView makes it really easy to create a nice animation using the hidden property of a UIView. I have two UIStackViews each with UILabels in the arrangedSubviews and when I add a new UILabel to a UIStackView, it should present it with an…
Casse
  • 51
  • 1
  • 6
5
votes
1 answer

How to embed stack view in scroll view programmatically

I have tried embedding it, but my stack view is dynamic and my app is also changing orientations time to time. I have segment control at the end of the view. I have also tried googling it but had no luck. thanks in advance. So far I have done: In…
shafi
  • 426
  • 3
  • 15