iOhYes Retired


A podcast by iOS developers for iOS developers, delivering news, tips, and rants for professional iOS/Mac developers, with something for enterprise and indie developers alike.

Hosted by Darryl Thomas and John Sextro.

← Previous Episode   |   Next Episode →

107: Hit the TIE Fighter

April 13, 2016 at 8:15AM • 1 hour 17 minutes • Wiki Entry


Auto Layout

  • Stack Views, FTW (Auto Layout without constraints) (New in iOS 9, similar to what’s available in watchOS and NSStackView, which is available from OS X 10.9)
  • UILayoutGuide
    • New in iOS 9
    • Defines a rectangular geometry that can interact with Auto Layout
    • Eliminates the need (in many cases, at least) for views that are included solely for layout purposes (container views, spacing views, etc)
    • Views can still provide a greater degree of encapsulation
    • Provide anchors that can be used to generate constraints
  • Anatomy of constraints
    • The layout of your view hierarchy is defined as a series of linear equations. Each constraint represents a single equation. Your goal is to declare a series of equations that has one and only one possible solution.
    • Two basic types of attributes
  • Size attributes (for example, Height and Width)
  • Location attributes (for example, Leading, Left, and Top)
  • The following rules apply:
    • You cannot constrain a size attribute to a location attribute.
    • You cannot assign constant values to location attributes.
    • You cannot use a nonidentity multiplier (a value other than 1.0) with location attributes.
    • For location attributes, you cannot constrain vertical attributes to horizontal attributes.
    • For location attributes, you cannot constrain Leading or Trailing attributes to Left or Right attributes.
  • Rule of Thumb for clarity
    • Whole number multipliers are favored over fractional multipliers.
  • Positive constants are favored over negative constants.
  • Wherever possible, views should appear in layout order: leading to trailing, top to bottom.
  • Constraint Priorities
    • 1000 is required
    • < 1000 is optional
  • Intrinsic Content Size
    • Content Compression Resistance
    • Content Hugging
  • Debugging Auto Layout
    • Error Types
      • Unsatisfiable Layouts. Your layout has no valid solution.
        • Usually 2 or more required constraints conflict
    • Ambiguous Layouts. Your layout has two or more possible solutions.
        * Need additional constraints
      • conflicting optional constraints
    • Logical Errors. There is a bug in your layout logic.
  • Tips and Tricks
    • take advantage of the logs
    • use meaning identifiers on views and constraints
    • Debug > View Debugging > Show Alignment Rectangles





Show Notes & Links Presented by CacheFly

Tweet Shoutouts