I'm working in Xcode 10 and am getting some errors when trying to add some pretty simple constraints to my view.
I have a UICollectionViewCell
that I'm adding a UIStackView
to. I size the UIStackView
to fill the cell and set the top, bottom, left, and right constraints to the Safe Area.
I used to be able to do this in Xcode 9 without error, however, it now gives me an error that I need to specify the X Position or Width and the Y Position or Height. Even when I let the interface builder add the missing constraints (Center X and Center Y) it gives the same error. I feel like this is a bug in Xcode 10, but if there are new iOS 12 requirements for constraints I don't know about I'd appreciate some help with them.
If I ignore the erroneous constraints and run the app the view does not show up properly.
UPDATE
I definitely think this is a bug. Notice in the screenshot below, even though I have subviews in the stack view, the errors do not go away. Also, when I add static padding to the top, left, bottom, and right it does not show properly in the layout, however it does layout properly when I run the app.
To create constraints select the button and click the Align icon in the auto layout menu. A popover menu will appear, check both “Horizontal in container” and “Vertically in container” options to center the button on the screen. Then click the “Add 2 Constraints” button.
You can correct this by pressing Command + Option + = or selecting "Update Frames" in the |-•-| menu (I think it looks like a tie fighter).
Basically if the layout margins are 8,8,8,8 (the default), a constraint with 0 leading space to container margin will have an x position of 8. Note that this is only available on iOS8 or later.
This is, indeed, a bug in Xcode 10. To resolve this issue, embed the stack view in another view, which has the same constraints as the stack view before:
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