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

Adding views dynamically to UIStackview

I'm trying to add views(or buttons) to UIStackView dynamically. At first, the UIStackView has no arranged views (vertically), and after getting from some http response, several views(buttons) are added to UIStackView. UIStackView is also…
GT Kim
  • 329
  • 1
  • 4
  • 16
6
votes
3 answers

iOS 11 UIStackView fill proportionally distribution causes weird view loading animation

If I set: stackView.distributon = .fillProportionally Then on iOS 11 I get a very weird animation when loading a view that contains this stack view (all subviews - not just stack view - are flying from the top or bottom of the screen). On lower…
kiwisip
  • 437
  • 1
  • 4
  • 12
6
votes
1 answer

Swift UIStackView: Positioning elements from center programmatically

I am trying to get elements inside a UIStackView to position themselves equally from the center. This is the desired effect I would like: As you can see, I would like the two text fields to be equally spaced from each other and aligned center…
JamesG
  • 1,552
  • 8
  • 39
  • 86
6
votes
0 answers

Dynamically change axis in UIStackView

I have 2 views in a horizontal UIStackView. What I'm trying to achieve is for the stack view to stay in horizontal mode if possible, but if this isn't possible then change to a vertical mode. Demonstrated in the image below. When in the second case…
Ben Easton
  • 195
  • 8
6
votes
2 answers

UIStackView moves it's arranged subviews to top left when all subviews are hidden within an animation block

If I try to animate the hiding all the subviews of a stackview, I can see them moving towards the top left corner. On showing, they are animated coming from top left to their proper space. If I hide only a subset of the arranged views, they are…
Морт
  • 1,163
  • 9
  • 18
6
votes
3 answers

UITableView not shown inside UIStackView

I have a UIStackView where it can show a label, image, table view or nothing based on user selection. Here is my current hierarchy for the dynamic view: UIStackView_Parent UILabel - some text, fixed view UIStackView_Child - this is the container…
Joe L
  • 83
  • 1
  • 2
  • 7
6
votes
2 answers

Animate DatePicker hide/show in StackView

How to properly animate datePicker appearance/disappearance in stackView? Currently I tried like this: UIView.animateWithDuration(0.3, animations: { self.datePickerView.hidden = !self.datePickerView.hidden }) This causes problems with hiding…
Xernox
  • 1,706
  • 1
  • 23
  • 37
6
votes
3 answers

How to fill iOS Stack View (UIStackView) with an image as a background?

I want to set stack view background to an image. For example, in Android, if I use 'Linear Layout' (equivalent to UIStackView), I can set a background image to the 'Linear Layout' irrespective of whatever the content (views) I add to it. How could I…
kalan nawarathne
  • 1,944
  • 27
  • 26
6
votes
1 answer

UIStackview with differently aligned subviews

I'd like to align the Blue and Purple views to the center of the screen, and I'd like to align the green view to the left of the screen: Here is my code: view.backgroundColor = UIColor.orangeColor() //Stackview: let stackView =…
Eric
  • 16,003
  • 15
  • 87
  • 139
6
votes
1 answer

UIStackView before iOS 9.0 in Xcode 7 beta 5

I'm using Xcode 7 beta 5, and I'm getting an error that says "UIStackView before iOS 9.0". I see that at least one other person has had this problem, but their solution isn't working for me. My deployment target is 9.0. Here's a link to some helpful…
Spencer Goff
  • 1,036
  • 3
  • 14
  • 23
6
votes
1 answer

How can Xcode 7 Stack Views be backwards-compatible with iOS 8 and iOS 7?

I watched the WWDC video #407 - "Implementing UI Designs in Interface Builder" that present the cool feature - "Stack Views", and I was wonder that it would be wonderful (if it is possible) to build apps that will run on iOS 7, and 8 and take…
Shlomi Hasin
  • 443
  • 7
  • 12
5
votes
1 answer

Ambiguous UILabel height in autoresizing UITableViewCell

I am having a hard time making my implementation of UITableView with automatic cell sizing. I am trying to use a UIStackView with 2 labels inside cell with automatic size. It looks good overall but I am getting the following runtime issues: I feel…
5
votes
1 answer

UITableView with accordion-like animation of cells with dynamic height

I'm trying to create an accordion-like animation inside a UITableView with cells of dynamic height. First attempt using reloadRows The issue seems to be that reloadRows results in an instant cell height update, so although the tableview animates,…
Mads Mobæk
  • 34,762
  • 20
  • 71
  • 78
5
votes
5 answers

Add layoutMargins to one element in a UIStackView

I would like to create a vertical stackview with 3 elements in it. I want a bit more space only between the 2nd and the last element. So I thought about adding to the last element : mylastelement.layoutMargins = UIEdgeInsets(top:30,…
Jerem Lachkar
  • 1,008
  • 11
  • 24
5
votes
2 answers

Custom interfaces for Portrait & Landscape mode iOS

I am trying to layout user interfaces differently for Portrait & Landscape orientations. The difference comes in the following ways: I have few UIStackViews. Some of their axis becomes horizontal in landscape but vertical in portrait mode, The…
Deepak Sharma
  • 5,577
  • 7
  • 55
  • 131