Learn Modern Auto Layout For iOS
Using Auto Layout? How many of these do you recognize?
⚠️ Randomly adding and removing constraints to get the layout you want
⚠️ Changing content hugging and compression priorities but not sure why?
⚠️ Conflicting constraints and a wall of debug text dumped to the console?
⚠️ Got a layout working on the iPhone but it looks terrible on the iPad and breaks on that tiny iPhone SE screen
⚠️ You want to add dynamic type for your users but there's no way that super-gigantic text size is going to fit
Add a constraint – Change a priority – See what happens…
You can try to work logically. But… Honestly adding constraints still feels like guesswork. Where do you start? When is it done?
Auto Layout is just too magical for your liking
Want to Auto Layout like a pro? Build flexible layouts that work everywhere? But feel like… you’re going in circles.
Learn to ❤️ Auto Layout
What if you knew how to approach a layout with confidence. You knew which constraints to add. When to squeeze a view and when to stretch it. You Know When You’re Done.
You’re cool with storyboards and relaxed about building layouts in code.
Let’s also make your layout adapt to dynamic type, different devices, and screen sizes.
It’s true that learning Auto Layout can make your head spin. But it doesn’t have to be that way…
Let me teach you modern Auto Layout...
The Key Principles You Need to Know
We start with topics often ignored. Learn how the view layout system works. The fundamental principles that turn Auto Layout into something predictable you can understand.
Learn what constraints you need to fully size and position a view. How to create them. Where to add them. How many you need.
Create Constraints The Easy Way
Auto Layout has changed a lot. Learn Modern Auto Layout with layout anchors and guides, stack views, safe areas, and size classes. Flexible layouts. Less work. Less boilerplate.
(No you don’t need to learn the Visual Format Language)
Take Your Pick - Code Or Interface Builder
Learn to create layouts in Interface Builder and programmatically. Use what works for you but know how to switch when you have to.
Learn By Doing
Practice makes perfect. Sharpen your Auto Layout skills with challenges that get you solving common layouts. Hints And Tips when you need them. Compare with my solution when you’re done.
Your Users Will Thank-You
Go the extra mile. Support dynamic type. Use layout variations, scrolling, and self-sizing table view cells. Create layouts that work from the smallest iPhone to the largest iPad.
Buy Modern Auto Layout
Get to grips with Modern Auto Layout and keep your designers, your users (and yourself) happy. Buy my book and start creating layouts that you'll be proud of today.
- Multiple formats: PDF (480 pages), ePUB (iBooks) and MOBI (Kindle)
- DRM free. Read on all of your devices that support PDF, ePUB or MOBI formats, without restriction.
- Updated for Xcode 11, Swift 5 and iOS 13.
- 80 sample Xcode projects available for download from the book's source code repository.
- 32 layout challenges to practice your layout skills as you learn. Full solutions in the book's source code repository.
What's In The Book?
Here's what you'll learn from the book:
Layout Before Auto Layout
- How did layout work before Auto Layout?
- Using autoresizing masks
- How to subclass UIView and make friends with layoutSubviews
- How to build programmatic layouts without storyboards
Getting Started With Auto Layout
- What is Auto Layout?
- What is a constraint?
- Who owns a constraint?
- How many constraints do I need?
Using Interface Builder
- The many ways to create and edit a constraint
- Viewing layout warnings and errors
- Interface Builder tips and tricks
Creating Constraints In Code
- How best to activate and deactivate constraints
- Disabling the autoresizing mask (you will forget)
- Creating constraints with NSLayoutConstraint, Visual Format Language and Layout Anchors
- Which should you use? (Take a guess...)
Safe Areas And Layout Margins
- Safe area layout guides - embrace the notch!
- Layout margins everywhere
- Layout guides... goodbye spacer views?
Layout Priorities And Content Size
- Layout priorities - as close as possible please...
- Intrinsic content size - the natural size
- Content mode - fit, fill, redraw...
- Content hugging and compression resistance - don't stretch me, don't squeeze me!
- Get started with stack views...
- ...then dive deeper
- Dynamically updating stack views
- Adding background views
- Stack view oddities - nobody's perfect
Understanding The Layout Engine
- The layout pass - what's going on?
- Why you probably don't need updateConstraints
- Animating constraints
- Get fancy with custom layouts
- Alignment rectangles - bring back the shadow
Debugging When It Goes Wrong
- Unsatisfiable constraints
- How to add identifiers to views and constraints
- Ambiguous layouts - tell me more!
- Using the view debugger
- Private debug methods - keep them to yourself.
- Layout loops...layout loops...layout loops
Scroll Views And Auto Layout
- Creating constraints for a scroll view - who would have guessed that's how it works?
- Scrolling a stack view
- Frame and content layout guides (new in iOS 11 - hooray)
- Managing the keyboard - even when you don't think you need to...
- Using dynamic type - make your users happy
- Taming long lines with readable content guides
- Text views vs text labels - how to choose?
- Scaling dynamic type
- Custom fonts with dynamic type when you're bored with San Francisco
Working With Table Views
- Self-sizing table view cells. How to get them to work.
- Readable table views. Did you spot the change in iOS 12?
- Self-sizing table view headers and footers
Adapting For Size
- Trait collections and size classes
- Supporting iPad multitasking
- Using size classes with Interface Builder and in code
- Using traits with the asset catalog
- Variable width strings - how many em's is that?
- When size classes are not enough
Sample Code And Challenges To Test Your Knowledge
- Challenges to test your knowledge as you learn
- Hints and tips so you don't get stuck
- Full sample code and solutions
- Interface Builder and programmatic layouts
- A tour of Interface Builder
- Layout essentials - what you need to know about the view hierarchy and view geometry
- Points vs pixels - what's the difference?
Download a preview with the full table of contents, introduction, and chapter 7 on layout priorities.
Updates to the book are free. You'll be able to download them from your Gumroad account. This includes any updates for changes Apple makes to Xcode, iOS and Swift.