IOS Auto Layout Demystified

Front Cover

Book Description

Completed Updated for iOS 7 and Xcode 5

Auto Layout transforms the way you create iOS user interfaces. As flexible as it is powerful, Auto Layout gives you unprecedented control over your iOS user interfaces. But Auto Layout has a reputation for difficulty. In iOS Auto Layout Demystified, Second Edition, world-renowned iOS developer and author Erica Sadun strips away the confusion, helping you gain Auto Layout mastery the easiest way possible: by example.

Fully updated for iOS 7 and Xcode 5, this tutorial delivers everything Sadun’s guides are famous for: clear explanations, expert tips, proven best practices–and, above all, plenty of code to learn from and reuse.

Step by step, Sadun explains how Auto Layout “thinks,” how it works, where it fits, and why it’s more useful (and simpler) than you ever imagined. She offers practical solutions for a wide variety of real-world iOS development challenges, plus innovative ways to use Auto Layout to build interactive elements, animations, and more.

If you’re an experienced iOS developer, this guide will expand your design possibilities, helping you build apps that are superbly usable and intuitive and stand out even in the most crowded marketplace.

Coverage includes

  • Mastering Auto Layout’s basic concepts, techniques, and approach
  • Defining unambiguous, satisfiable constraints that express your layout exactly how you intend
  • Overcoming obstacles to constraint-based user interface design in Interface Builder
  • Using visual formatting to express how items are laid out vertically and horizontally
  • Making visual formats more flexible with metrics dictionaries and layout options
  • Debugging constraints and deciphering those bewildering Xcode log messages
  • Using descriptive techniques to uncover and express natural relationships in your design
  • Applying iOS Auto Layout techniques in Mac OS X apps too

Table of Contents

  1. About This eBook
  2. Title Page
  3. Copyright Page
  4. Dedication Page
  5. Table of Contents
  6. Preface
    1. How This Book Is Organized
    2. About the Sample Code
    3. Getting the Sample Code
    4. Getting Git
    5. Getting GitHub
    6. Contribute!
    7. Contacting the Author
    8. Editor’s Note: We Want to Hear from You!
  7. Acknowledgments
  8. About the Author
  9. 1. Introducing Auto Layout
    1. Origins
    2. Saying “Yes” to Auto Layout
    3. Constraints
    4. Constraint Attributes
    5. About Those Missing Views
    6. Ambiguous Layout
    7. Intrinsic Content Size
    8. Compression Resistance and Content Hugging
    9. Image Embellishments
    10. Exercises
    11. Conclusions
  10. 2. Constraints
    1. Constraint Types
    2. Priorities
    3. Content Size Constraints
    4. Building Layout Constraints
    5. The Layout Constraint Class
    6. Creating Layout Constraints
    7. View Items
    8. Constraints, Hierarchies, and Bounds Systems
    9. Installing Constraints
    10. Comparing Constraints
    11. Laws of Layout Constraints
    12. Exercises
    13. Conclusions
  11. 3. Interface Builder Layout
    1. Designing in IB
    2. Disabling Auto Layout
    3. Basic Layout and Auto-Generated Constraints
    4. A Guided Tour of IB Elements
    5. Adding Constraints
    6. Previewing Layouts
    7. Inspecting Constraints
    8. View Size Inspector
    9. The Resolution Menu
    10. Constraints/Resizing Pop-Up Menu
    11. The Missing Views Problem
    12. Balancing Requests
    13. Hybrid Layout
    14. Removing IB-Generated Constraints
    15. Exercises
    16. Conclusions
  12. 4. Visual Formats
    1. Introducing Visual Format Constraints
    2. Options
    3. Variable Bindings
    4. Metrics
    5. Format String Structure
    6. Orientation
    7. View Names
    8. Connections
    9. View Sizes
    10. Format String Components
    11. Getting It Wrong
    12. NSLog and Visual Formats
    13. Constraining to a Superview
    14. View Stretching
    15. Constraining Size
    16. Building Rows or Columns
    17. Matching Sizes
    18. Why You Cannot Distribute Views
    19. Exercises
    20. Conclusions
  13. 5. Debugging Constraints
    1. Xcode Feedback
    2. Reading Console Logs
    3. Examining Constraint Logs
    4. A Note About Layout Math
    5. Constraint Equation Strings
    6. Adding Names
    7. Describing Views
    8. Unexpected Padding Example
    9. The Hugged Image Example
    10. View Centering Example
    11. Descent Reports
    12. Ambiguity Example
    13. Expanding on Console Dumps Example
    14. Visualizing Constraints
    15. Launch Arguments
    16. Internationalization
    17. Profiling Cocoa Layout
    18. Auto Layout Rules of Debugging
    19. Exercises
    20. Conclusions
  14. 6. Building with Auto Layout
    1. Basic Principles of Auto Layout
    2. Layout Libraries
    3. Planning Interfaces
    4. Building for Modularity
    5. Updating Constraints
    6. Designing for Edge Conditions
    7. Building a View Drawer
    8. Window Boundaries
    9. Exercises
    10. Conclusions
  15. 7. Layout Solutions
    1. Table Cells
    2. Preserving Image Aspect
    3. Accordion Sizing
    4. Scroll Views
    5. Centering View Groups
    6. Custom Multipliers and Random Positions
    7. Building Grids
    8. Making Room for the Keyboard
    9. Inserting Views at Runtime
    10. Motion Effects, Dynamic Text, and Containers
    11. Exercises
    12. Conclusions
  16. A. Answers to Exercises
    1. Chapter 1
    2. Chapter 2
    3. Chapter 3
    4. Chapter 4
    5. Chapter 5
    6. Chapter 6
    7. Chapter 7
  17. Index