Why are constraints disabled for a view in XCode?

43 views Asked by At

In an existing Swift for macOS project, I have added a xib file to play around with window and view layouts. I have create a window with a view, and added a button. Now I want to connect the anchors. But the constraints are disabled.

What is required in a view/window to enable the usage of constraints?

Disabled constraints

1

There are 1 answers

1
rein On

The ones that are disabled in your screenshot require two controls to be selected since they are constraints that deal with the alignment between two controls.

If you want to create anchors between the button and the parent view, simply ctrl-drag from inside the button to the parent view and choose the constraint you would like from the popup:

Create constraints

Or, alternatively, use the Add New Constraints button instead of the Align button:

enter image description here