Adding autolayout constraints


#1

On page 268 of the second edition, the book reads "Autolayout constraints are added individually, and Control-Shift-clicking to select the scroll view in the layout grid is tiresome… " and then proceeds to add constraints individually through the menus… this is tiresome indeed…

Using X-Code, the user can add autolayout contraints for the entire view, with one click…

Click on the view so that a blue line appears around it. (or Control-Shift click and select NSWindow)

This will enable a set of four constraint icons near the bottom of the editor. Click on the button which “looks like a Ti-Fighter” (a circle with a sideways T on each side. The button help says “Resolve Auto Layout Issues”). This will bring up a menu. Select “Reset to suggested constraints in window”.

Now run the program, resize and everything in the window scales correctly if you adhered to blue lines…

One click, the whole thing is done.

You can use this button and the Pin button (to the left) for constraint adjustment of all items on the screen individually too.