In Practical Auto Layout for Xcode 8, using simple, practical, easy to follow examples, you will learn how to master auto layout and size classes on the Xcode 8 storyboard. You will learn how to make universal apps quickly easily and in far less time than ever before. You’ll learn how to use constraints the right way, how to avoid and resolve errors such as misplacements and conflicting constraints. You be able to customize your layout for both launch screens and your application, using buttons, labels, images, text fields and more.
You’ll learn more than just simple layout. You’ll earn how to use stack views and iPad multitasking. You’ll size images the right way without distortion. Practical Auto Layout for Xcode 8 covers what you need to know about multitasking on the iPad for the best user experience and how little you have to do to make this a powerful addition to your app.
Practical Auto Layout for Xcode 8 shows you how to use all these tools effectively to make layouts that work on all devices in minutes.
A tech author’s work is never done. As soon as he or she completes manuscript and gets it published, the manuscript almost immediately becomes obsolete. In my case, Practical Autolayout for Xcode 8 went obsolete a day before I published, but I had no idea about a major change in Xcode 8.1.
So where did it go?
Apple moved this to an icon on the auto layout toolbar and deleted it from the menus.
If it were me, I wouldn’t have deleted it from the menus in such an abrupt way. Apple did. This Update Frame button has some different behaviors from its predecessor on the menu, and I’d like to explain that using some examples from Chapter 3 of Practical Autolayout for Xcode 8
Set up a storyboard that looks something like this with a label Hello Pizza, a text view, and three buttons, Pepperoni, Cheese, and Done:
Add the 3 constraints. The Hello Pizza Label will show misplacement constraints.
This is not always the result. You must have all constraints satisfied before the button will update frames. For example, select the text view. Press the align button and center the text view by checking on Horizontally in Container and Vertically in Container.
Again don’t update frames, but click Add 2 constraints. You’ll see an ambiguous constraint in red.
If you click the button nothing happens. Until a frame has no ambiguity(i.e. no red constraint errors), you cannot update it. Most often that is setting a size. For the text box, set an absolute size in the pin menu of 175 points in both directions.
Add the constraints. The errors all turn to misplacements.
Priorities are not assumed with the new update frames button. When there is an ambiguity in size between two frames that depend on each other for size, you must specify the a priority for them or set a size. Take for example these two buttons.
Pepperoni is pinned to the left margin, the label above it and the text view below it. Cheese is pinned 10 points from Pepperoni, aligned to the top of Pepperoni, and pinned 10 points from the right margin. We’d like to have two buttons that fill the available space.
The option used in Practical Auto Layout for these buttons is to make them the same size. Control drag from Pepperoni to Cheese. A menu appears.
Shift select Equal Width and Equal Heights, then hit the Add Constraints selection. The ambiguity changes to misplacements.
The other, more advanced option is to change priority of one of the buttons so they are not equal. Both are by default 250. Going back to the original ambiguous layout,
changing the content hugging priority of Pepperoni from 250 to 251 tells auto layout for Pepperoni to keep its size and Cheese to stretch to make up the difference.
Priorities are covered in detail in Chapter 12 of Practical Autolayout for Xcode 8.
I’ll be updating the book shortly. Until then or if you cannot update your book, consider this an errata to the versions now available.
Purchase the book for Kindle and iTunes here: