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
279
votes
20 answers

Is it possible for UIStackView to scroll?

Let's say I have added more views in UIStackView which can be displayed, how I can make the UIStackView scroll?
itsaboutcode
  • 24,525
  • 45
  • 110
  • 156
206
votes
22 answers

Multiline label in UIStackView

When putting multiline label (with linebreak set to Word Wrap) into a stack view, the label immediately loses the linebreak and displays the label text in one line instead. Why is this happening and how does one preserve multiline label within a…
Boon
  • 40,656
  • 60
  • 209
  • 315
203
votes
17 answers

Add views in UIStackView programmatically

I'm trying to add views in UIStackView programmatically. For now My code is: UIView *view1 = [[UIView alloc]init]; view1.backgroundColor = [UIColor blackColor]; [view1 setFrame:CGRectMake(0, 0, 100, 100)]; UIView *view2 = [[UIView…
Altimir Antonov
  • 4,966
  • 4
  • 24
  • 26
195
votes
13 answers

How to add leading padding to view added inside an UIStackView

This is my setup: I have an UIScrollView with leading,top, trialing edge set to 0. Inside this I add an UIStackView with this constraints: stackView.centerYAnchor.constraintEqualToAnchor(selectedContactsScrollView.centerYAnchor).active = true …
Adrian
  • 19,440
  • 34
  • 112
  • 219
184
votes
22 answers

How to change the background color of UIStackView?

I tried to change the UIStackView background from clear to white in Storyboard inspector, but when simulating, the background color of the stack view still has a clear color. How can I change the background color of a UIStackView?
LukasTong
  • 1,861
  • 2
  • 10
  • 7
111
votes
6 answers

UIStackView Hide View Animation

In iOS 11 the behaviour of the hide animation within a UIStackView has changed, but I have been unable to find this documented anywhere. iOS 10 iOS 11 The code in both is this: UIView.animate(withDuration: DiscoverHeaderView.animationDuration, …
Infinity James
  • 4,667
  • 5
  • 23
  • 36
102
votes
14 answers

UIStackView "Unable to simultaneously satisfy constraints" on "squished" hidden views

When my UIStackView "rows" are squished, they throw AutoLayout warnings. However, they display fine and nothing else is wrong besides these sorts of loggings: Unable to simultaneously satisfy constraints. Probably at least one of the…
Ben Guild
  • 4,881
  • 7
  • 34
  • 60
97
votes
9 answers

UIStackView : Is it really necessary to call both removeFromSuperView and removeArrangedSubview to remove a subview?

From the UIStackView Class Reference In removeArrangedSubview: To prevent the view from appearing on screen after calling the stack’s removeArrangedSubview: method, explicitly remove the view from the subviews array by calling the view’s…
robola
  • 975
  • 1
  • 6
  • 9
90
votes
6 answers

How can I create UIStackView with variable spacing between views?

I have a simple horizontal UIStackView with several UIViews stacked inside. My goal is to create variable spacing between views. I am well aware that I can create constant space between the subviews using "spacing" property. However my goal is to…
yura
  • 1,474
  • 1
  • 12
  • 16
61
votes
4 answers

changing property contentsGravity in transform-only layer, will have no effect

I started to create a very simple tic-tac-toe game. The main goal is to make the view proportional to all screen sizes of all iOS devices. So I put the image on a ViewController, make it full size of screen and then I put it into a Stack View. I've…
Alex Belke
  • 2,143
  • 5
  • 17
  • 24
51
votes
2 answers

IOS stackview addArrangedSubview add at specific index

How is it possible to add a arranged subview in a particular index in a UIStackView? something like: stackView.addArrangedSubview(nibView, atIndex: index)
Elton Santana
  • 950
  • 3
  • 11
  • 22
45
votes
6 answers

Remove views in UIstackview swift

I am new to swift. I have added view to stackview using addArrangedSubview(). But I am not able to remove this view using removeArrangedSubview(). Even after removing arranged subView the view is still present import Foundation import UIKit class…
Ahalya Hegde
  • 1,571
  • 2
  • 18
  • 41
40
votes
7 answers

Nested UIStackViews Broken Constraints

I have a complex view hierarchy, built in Interface Builder, with nested UIStackViews. I get "unsatisfiable constraints" notices every time I hide some of my inner stackviews. I've tracked it down to this: ( "
Alex Popov
  • 2,509
  • 1
  • 19
  • 30
40
votes
4 answers

Can UIStackView support iOS 8 or 7?

I know that UIStackview is a new feature in iOS 9. If I want my app to support iOS 8 or iOS 7, does that mean I shouldn't use stack views?
Ted
  • 22,696
  • 11
  • 95
  • 109
36
votes
9 answers

Can you give UIStackView borders?

I'm trying to give 5 separate UIStackViews in my ViewController borders. I gave each of them an IBOutlet and then called them in viewDidLoad to use the layer property but to no avail. Is it not possible to give stack views borders,…
pmoney13
  • 1,075
  • 3
  • 11
  • 19
1
2 3
95 96