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

Are you supposed to add constraints to subviews of a Stackview?

... because I have an image view that's centered horizontally to its parent, and it's appearing right aligned.
Ian Warburton
  • 15,170
  • 23
  • 107
  • 189
7
votes
1 answer

Create Vertical lines between Uilabels inside of a stack view

I want to create a UICollectionView with a custom header in Code. Therefore i created a Subclass of UICollectionViewCell to describe my custom header. I want to display five labels in my header in a horizontal line. Therefore I created five labels…
Developer Omari
  • 434
  • 5
  • 14
7
votes
1 answer

Get the frame of a UIStackView subViews

I have created a UIStackView in IB which has the distribution set to Fill Equally. I am looking to get the frame for each subView but the following code always returns (0, 0, 0, 0). class ViewController: UIViewController { @IBOutlet weak var…
Wozzer
  • 73
  • 1
  • 1
  • 5
7
votes
4 answers

Swift: Crash on removeFromSuperview()

Problem: App crashes when I attempt to remove subview. Context: I have a UICollectionViewCell that gets updated with a model object. I've tried putting these methods in prepareForReuse and/or the update(model: viewModel) method. Notes: The line That…
Emin Israfil iOS
  • 1,801
  • 1
  • 17
  • 26
7
votes
0 answers

Drag and Drop Image from UICollectionView to UIView?

Is it possible to drag an image from a collectionViewCell into a UIView? I am creating a game where the user can pick a number of items to play with in the next VC. I'm representing each item as an image and the user can select each item by…
7
votes
1 answer

Constraint error for UIScrollView with an empty UIStackView in Interface Builder

I'm following the "Dynamic Stack View" part of this Stack View Apple tutorial, and I'm running into an constraint issue in Interface Builder if I leave the UIStackView (within the UIScrollView) empty, as opposed to putting a UIButton inside it. I…
solidcell
  • 7,639
  • 4
  • 40
  • 59
7
votes
1 answer

UIStackView not updating after updating height of subview (UITableView with no scroll) while inside a ScrollView

How to make a UIStackView re-distribute it's sub-UITableViews while the stackView is inside a scrollview? My layout hierarchy is based on the official documentation from apple about Dynamic content for StackViews - UISCrollView - UIStackView …
Tom Bevelander
  • 1,686
  • 1
  • 22
  • 31
7
votes
1 answer

Solving UIStackView Layout Ambiguity

I have a custom UITableViewCell that has the following elements: UIImageView UILabel UILabel I want the UIImageView on the left, and the 2 UILabel objects stacked one on the other on the right side. Here's what it looks like in the…
Kelvin Lau
  • 6,373
  • 6
  • 34
  • 57
7
votes
1 answer

Is there a way to access the priority of constraints placed by UIStackView?

I'm getting "Unable to simultaneously satisfy constraints" when using UIStackView's .hidden property. I know it's because since I set Distribution to "fill equally" and the Spacing to 1 and then hide the UIStackView it tries to set its height to…
DigitalDeath
  • 155
  • 1
  • 11
7
votes
3 answers

UIStackView children equally spaced (around and between)

How can I have an UIStackView with the same space as padding and gap between views? How can I achieve this layout: When this one doesn't suit me: Neither does this: I just need the around views space to be the same as the between views space. Why…
gfpacheco
  • 2,831
  • 2
  • 33
  • 50
7
votes
1 answer

How do I by code add a change to UIStackView.Axis on orientation change?

I have a few UIStackView that I add programmatically and I want them to have a other Axis when the app is in say Regular Width and Any Height. It this even possible, like it is in the interface builder? All I bump into on Google is…
Bjarte
  • 2,167
  • 5
  • 27
  • 37
7
votes
1 answer

how to use Stack View of object library in Xcode 7

I recently installed Xcode 7 beta and found something new in object library like Horizontal stack view and Vertical stack view. When i put some controls inside it, stackview seems to be resizable according to the control size. When i present…
ak2g
  • 1,673
  • 15
  • 22
6
votes
3 answers

UIStackView not calling draw of custom UIView

I have a UIView with a custom draw(_ rect: CGRect) method, which works. However, when I place it inside a UIStackView, its draw method is not called. UILabel or UIImage inside the same stack view display normally. In Interface Builder, it is drawn…
Dieter Baron
  • 101
  • 3
6
votes
1 answer

Swift: UIStackView of UIControls with selector method that doesn't fire

Introduction I'm creating an app which uses a custom view in which I have a UIStackView to sort out 5 UIControls. When a user taps one of the UIControls an underscore line gets animated, sliding under the tapped UIControl. However, for some reason…
theoadahl
  • 504
  • 4
  • 21
6
votes
2 answers

UIStackView: Loading views from xib and updating height constraint of subView did not reflecting any changes?

I have the following hierarchy in my application - UIScrollView - UIStackView - UIView 1 // load with xib and added in arrangedSubviews - UIScrollView 1.1 // horizontal scrolling, fixed height constraint 38 - UIView 1.2 // called it…
iamVishal16
  • 1,780
  • 18
  • 40