I'm trying to create a relatively simple (!) layout with iOS 9 Stack Views. This is the Storyboard:
With the following layout:
But it's ambiguous: Titles Stack View: Need constraints for: X position or width
, Times Stack View: Need constraints for: X position or width
. I don't understand why. I've set the horizontal content hugging priority of the Titles Stack View
to less than that of the Times Stack View
, what else do I need to do?
Ambiguous layouts occur when the system of constraints has two or more valid solutions. There are two main causes: The layout needs additional constraints to uniquely specify the position and location of every view.
Views and Constraints Begin by laying out the name rows in Interface Builder. Position the label and text field in their correct relative positions, select them both, and then click the Editor > Embed In > Stack View menu item. This creates a horizontal stack view for the 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.
Best use of stack view is that if you want to set multiple controls allinged vertically or horizontally to each other you just add all of them in stack view. stackview will handle its allignment you just need to give frame contraints to stackView.
My Times Stack View
alignment was set to Trailing
, setting it to Fill
fixed the problem.
(Though Xcode shows some of the views misplaced no matter what I do, but I'm putting this down as a bug)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With