height and vertical position are ambiguous for UIStackView
Asked Answered
B

3

15

Autolayout cannot figure out the height or vertical position of a UIStackView despite having added subviews.

This is a pretty common error and "gotcha" so please see the answer below.

Beastings answered 1/8, 2017 at 4:24 Comment(0)
B
23

If this is for a UIStackView make sure you are using addArrangedSubview and not addSubview

Beastings answered 1/8, 2017 at 4:24 Comment(0)
B
3

For me I received the following error:

warning: Ambiguous Layout: Position and size are ambiguous for 'Button'.

Where the button was placed inside a stack view in Interface Builder. The problem was that I had checked "Hidden" in Interface Builder which meant Xcode was freaking out saying position and size are ambiguous. Just uncheck "Hidden" on the stack view and the warning will disappear... Magic! ✨

Bundy answered 3/10, 2017 at 15:44 Comment(0)
C
0

As of XCode 12.3, you can control drag from your StackView to your View which will allow you to create constraints to resolve the warning:

https://i.sstatic.net/K2813.jpg

This will bring up this window which is helpful if you want to deal with leading/trailing space issues or centering:

https://i.sstatic.net/fdiBZ.jpg

Clarkia answered 18/2, 2021 at 21:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.