Flailing… • Over-specified Layouts • Mess around randomly with priorities • Lots of inequality constraints • “I don’t know why I need this, but it makes the debugger spew go away.”
Flailing… • Pixels end up in the correct place, but… • Layouts hard to maintain • Layouts hard to animate easily • Layouts do not describe higher-order relationships between views
More Optimal Than Before • Can cope cleanly with changes in size of outer view • Rotation on iOS or window resize on Mac • Layout captures higher-order relationships between views • Less random crap • Maybe still rely too much on fixed width/height constraints
Yet More Optimal Than Before • Can cope cleanly with changes to elements within the view • Localization • User-generated content • Dynamic Type • Design Changes and other maintenance • Things shouldn’t bump into each other or clip unnecessarily.
UIScrollView and Auto Layout • Apple TechNote 2154 • Two Approaches • HYBRID Make a subview with springs + struts, set contentSize to the size of that subview, and use auto layout only within the subview. • PURE Use Layout Constraints for everything!
UIScrollView and Auto Layout “Use constraints to lay out the subviews within the scroll view, being sure that the constraints tie to all four edges of the scroll view and do not rely on the scroll view to get their size.”
UITextField • Center Vertically in Layout Band • Fixed trailing space to superview • Leading edge tied to horizontal center of layout band (with offset) • looks decent landscape and portrait
UITextField • Text Field - same width and leading- align • Labels - same width and leading-align • allows labels to expand and still line-up UILabel UITextField UILabel