Making Sense of Auto Layout

Few features in Xcode are as controversial as Auto Layout. For every developer who swears by it, there seem to be at least two who swear at it.

Auto Layout is meant to solve a hard problem: where do you put your UI elements in a variable-size display? Of course, that means all the sizes of iPhones, including the iPhone X with its intrusive sensor housing (commonly known as “the notch”). But remember that Auto Layout is also used on the Mac, where the user can usually resize your window at any time.

If you want to master Auto Layout, start a macOS project, build a user interface in a window, and then grab the corner and start resizing it. Watch what happens, and if you see your UI components getting crushed or stretched, ...

Get Xcode Treasures now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.