Modern Auto Layout - Keith Harrison

Modern Auto Layout

von Keith Harrison

  • Veröffentlichungsdatum: 2023-11-21
  • Genre: Software

Beschreibung

Why is Auto Layout so hard?
See how many of these you recognize:

• Not sure when your layout is done or how many constraints you need?
• Feel like you’re randomly adding and removing constraints to get close to the layout you want?
• Changing content hugging and compression priorities but not sure why?
• Not sure what to do about 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 is going to fit.

You can try to work logically. But… adding constraints still feels like guesswork. Where do you start? When is it done?

Learning Auto Layout can make your head spin. But it doesn’t have to be that way…

Modern Auto Layout
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.
• Fully updated for Xcode 14, Swift 5 and iOS 16. Over 80 sample Xcode projects to download including full solutions to the layout challenges.

What’s In The Book?
The first part of the book covers the fundamentals of Auto Layout. The key concepts that make it work and the tools to apply it to your layouts:

• Layout before Auto Layout: We start by looking at how we did layout before Auto Layout, manually managing the frames of views and relying on autoresizing or when that’s insufficient, by overriding layoutSubviews. We also look at how to create an Xcode project to work without storyboards.
• Getting Started With Auto Layout: Introduces you to constraints, what they are, who owns them and how many you need to create common layouts.
• Using Interface Builder: We dive into using Interface Builder. We look at the many ways to create constraints and what the warnings and errors mean. We also have lots of useful tips and tricks to help you master Interface Builder.
• Creating Constraints In Code: You don’t have to use Interface Builder to use Auto Layout. Learn the three ways Apple gives us to create constraints in code and why you want to use layout anchors.
• Safe Areas And Layout Margins: Safe Area Layout Guides became a hot topic when Apple launched the iPhone X. Learn how to keep the system from clipping or covering your content. Learn how to use layout margins and layout guides including the keyboard guide introduced in iOS 15.
• Layout Priorities And Content Size: We cover the topics that cause many people to hate Auto Layout. The tricky concepts of layout priorities, intrinsic content size, and content-hugging and compression-resistance.
• Stack Views: Build layouts without having to manually create every constraint in Interface Builder or with pages of boilerplate code. We also cover some useful improvements that came in iOS 11 and some oddities to avoid.
• Understanding The Layout Engine: Time to dig deep into how the layout engine works to translate your constraints into a working layout. Why you probably don’t need updateConstraints, how to animate changes and take full control to build custom layouts.
• Debugging When It Goes Wrong: How do you debug your layouts when they go wrong? We look at the tools and techniques to understand and fix your Auto Layout problems.

With the foundation built the second part of the book looks at how to use Auto Layout with related API’s to build adaptive layouts.

• Scroll Views And Auto Layout: The scroll view is an essential view to master. We use it frequently in later chapters to build more adaptive layouts. It improved in iOS 11, but can still be confusing to use with Auto Layout.
• Dynamic Type: Dynamic type puts the user in control of the size of text in your App. Learn how to use dynamic type, adapt your layouts to cope with dramatic changes in text size and use custom fonts with dynamic type.
• Working With Table Views: Self-sizing table view cells are a regular source of pain and confusion. Learn how they work, how to use readable content guides with table views and add self-sizing headers and footers.
• Adapting For Size: We bring everything together to build layouts that adapt to the size of the screen. Learn how to use trait collections and size classes, create asset variations and variable width strings. Finally, we go beyond size classes to build adaptive layouts based on the available space.

Impressum und Kontakt

Software © by Hi Web Wiesbaden
Alle Rechte vorbehalten