iOS Auto Layout Demystified

iOS Auto Layout Demystified

by Erica Sadun

NOOK Book(eBook)

$22.49 $23.99 Save 6% Current price is $22.49, Original price is $23.99. You Save 6%.
View All Available Formats & Editions
Available on Compatible NOOK Devices and the free NOOK Apps.
Want a NOOK ? Explore Now


iOS Auto Layout Demystified by Erica Sadun

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

Product Details

ISBN-13: 9780133750782
Publisher: Pearson Education
Publication date: 10/28/2013
Series: Mobile Programming
Sold by: Barnes & Noble
Format: NOOK Book
Pages: 288
File size: 24 MB
Note: This product may take a few minutes to download.

About the Author

Erica Sadun is the bestselling author, coauthor, and contributor to several dozen books on programming, digital video and photography, and web design, including the widely popular The Core iOS 6 Developer's Cookbook, Fourth Edition. She currently blogs at and has blogged in the past at O'Reilly's Mac Devcenter, Lifehacker, and Ars Technica. In addition to being the author of dozens of iOS-native applications, Erica holds a Ph.D. in computer science from Georgia Tech's Graphics, Visualization, and Usability Center. A geek, a programmer, and an author, she's never met a gadget she didn't love. When not writing, she and her geek husband parent three geeks-in-training, who regard their parents with restrained bemusement when they're not busy rewiring the house or plotting global domination.

Table of Contents


Chapter 1: Introducing Auto Layout

Saying “No” to Auto Layout

Saying “Yes” to Auto Layout

             Visual Relationships

             Content-Driven Layout

             Prioritizing Rules

             Auto Layout Strengths




Constraint Attributes

Missing Views

             Underconstrained Missing Views

             Missing Views with Inconsistent Rules

             Tracking Missing Views

Ambiguous Layout

             Exercising Ambiguity

             Visualizing Constraints

Intrinsic Content Size

Compression Resistance and Content Hugging

Auto Layout and Frames

             Visualizing Alignment Rectangles

             Image Alignment Insets

             Declaring Alignment Rectangles

             Implementing Alignment Rectangles


Chapter 2: Constraints

Constraint Types


             Conflicting Priorities

             Enumerated Priorities

Content Size Constraints

             Content Hugging

             Compression Resistance

             Setting Content Size Constraints

Layout Constraints

             Constraint Math

The Layout Constraint Class

             First and Second Items

Creating Layout Constraints

Using NSLayoutConstraint

             Unary Constraints

             Zero-Item Constraints

View Items

Constraints, Hierarchies, and Bounds Systems

Installing Constraints

Removing Constraints

Comparing Constraints

             Using Matched Constraints

Laws of Layout Constraints


Chapter 3: Interface Builder Layout

Constraints in Interface Builder

             What’s What in the IB Editor

             Beginning Constraints

Constraint Listings

             Constraint Colors

             Constraint Icons

             Constraint Listings and Xcode Labels

             Adding Xcode Identities

Selecting Constraints

Inspecting Constraints

             The Constraint Attributes Inspector

View Size Inspector

             Frame and Layout Rectangles

             Constraint Options

Adding User Constraints

             Including Your Own Constraints

             Conflicting Constraints

Building New Constraints

The Missing Views Problem

Balancing Requests

             Balancing Constraint Priorities

Constraints and Outlets

Hybrid Layout

             Building a NIB File for Testing

             Adding the NIB File in Code

             Advantages of Hybrid Layout

Constraints/Resizing Pop-Up Menu


Chapter 4: Visual Formats

Introducing Visual Format Constraints



             Combining Options

             Skipping Options

Variable Bindings

             The Problem with Indirection

             Indirection Workaround


             Real-World Metrics

Format String Structure


             Retrieving Constraints by Axis

View Names



             Empty Connections

             Standard Spacers

             Numeric Spacers

             Referencing the Superview

             Spacing from the Superview

             Flexible Spaces


             Negative Numbers


             Multiple Views

View Sizes

Format String Components

Getting It Wrong

NSLog and Visual Formats

Constraining to a Superview

View Stretching

Constraining Size

Building Rows or Columns

Matching Sizes

Why You Cannot Distribute Views

             How to Pseudo-Distribute Views (Part 1: Equal Centers)

             Pseudo-Distributing Views (Part 2: Spacer Views)


Chapter 5: Debugging Constraints

Reading Console Logs

             Example: Autosizing Issues

             Solution: Switch Off Autosizing Translation

             Example: Auto Layout Conflicts

             Solution: Adjusting Priorities

             The Nuclear Approach

             The Balance Approach

             Tracing Ambiguity

Examining Constraint Logs

             Example: Alignment Constraint

             Example: Standard Spacers

             Example: Equation-Based Constraint

             Example: Complex Equation

             Example: The Multiplier and Constant

A Note about Layout Math

Constraint Equation Strings

Adding Names

             Using Nametags

             Naming Views

Describing Views

Example: Unexpected Padding

Example: The Hugged Image

Example: View Centering

             Retrieving Referencing Constraints

Descent Reports

Example: Ambiguity

Example: Expanding on Console Dumps

Visualizing Constraints

             Automating Visualization

Launch Arguments


             Doubled Strings

             Flipped Interfaces (OS X)

             Flipped Interfaces (iOS)

Profiling Cocoa Layout

Auto Layout Rules of Debugging


Chapter 6: Building with Auto Layout

Basic Principles of Auto Layout

Layout Libraries

Planning Interfaces

Building for Modularity

Updating Constraints

             Calling Updates and Animating Changes

             Animating Constraint Changes on OS X

             Fading Changes

Handling Orientation-Specific Text Layout

Designing for Edge Conditions

Building a View Drawer

             Building the Drawer Layout

             Managing Layout for Dragged Views

             Dragged Views

Window Boundaries


Chapter 7: Layout Solutions

Table Cells

Preserving Image Aspect

Accordion Sizing

Auto Layout

             Building a Paged Image Scroll View

             Inherent Drawbacks

Centering View Groups

Custom Multipliers and Random Positions

Building Grids

Constraint Animation on Steroids


Customer Reviews

Most Helpful Customer Reviews

See All Customer Reviews

iOS Auto Layout Demystified 5 out of 5 based on 0 ratings. 1 reviews.
Anonymous More than 1 year ago
Learn how to shoot a gun or enhance your kills here. No Killing.