What is auto layout?
a system that lets you lay out your
app’s user interface by creating a
mathematical description of the
relationships between the elements
define these relationships in terms of
constraints either on individual
elements, or between sets of elements
Slide 6
Slide 6 text
Constraints
Auto Layout
System
Layout
Slide 7
Slide 7 text
CE Level Math…
y = 7x + 3
y = -8x - 4
How to solve x and y?
Slide 8
Slide 8 text
What’s Constraint
view1.attribute1 = multiplier * view2.attribute2 + constant
An attribute is one of left, right, top, bottom, leading, trailing, width, height, centerX, centerY, and baseline.
e.g. the left edge of the button should be 20 points from
the left edge of its containing view
button.left = 1 * container.left + 20
y = m x + c
Slide 9
Slide 9 text
So…
Auto Layout is just to solve a large
number of linear equations
Cassowary constraint solver
http:/
/www.cs.washington.edu/
research/constraints/cassowary/
Slide 10
Slide 10 text
Why Auto Layout?
One day, designer Frank makes a brilliant design
All spacings are 20pt width
CE Level Math Revisit…
y = 7x + 3
y = 7x + 7
No Solutions
Slide 16
Slide 16 text
CE Level Math Revisit…
y = 7x + 3
2y = 14x + 6
Infinite Many Solutions
Slide 17
Slide 17 text
So What?
In Auto Layout
More than one solution
ambiguities
No solutions
unsatisfiable
Slide 18
Slide 18 text
Quiz
A label is constrained with 8-point
offsets from its superview’s left and
right edges. It is 22 points high.
Is this label’s layout ambiguous?
Slide 19
Slide 19 text
Quiz
Is this layout satisfiable?
button1.width = 2 * button2.width
button2.width = 3 * button1.width
Slide 20
Slide 20 text
Problem is …
They all are solution
ambiguous!!!!
Slide 21
Slide 21 text
Key Concept…
Correctly using auto layout requires
you to change thinking
Don’t go calculating frames
Define how elements are related
Describe the layout in a declarative
way
Slide 22
Slide 22 text
Top Layout Guide
Top Layout Guide
(0,0)
Slide 23
Slide 23 text
Intrinsic Content Size
Some views know their size
UIImageVIew
same as the image
UILabel
same as size of the text
Migration
Do I need to update all views to auto
layout system in one shot?
No
Will I miss anything after using auto
layout?
No, auto layout is more powerful
system than struts and springs
Slide 33
Slide 33 text
Localization
An attribute is one of left, right, top,
bottom, leading, trailing, width,
height, centerX, centerY, and
baseline.
Slide 34
Slide 34 text
No content
Slide 35
Slide 35 text
Useful usage
Slide 36
Slide 36 text
R Y
D
A
E
Zero Spacing Constraint
Center Vertically Constraint
Horizontal Vertically Constraint
Slide 37
Slide 37 text
Useful usage
Possible Solution:
1. WebView
2. Attributed String
!
Problem:
Note name has to be
center horizontally
Slide 38
Slide 38 text
Auto Layout Solution
Slide 39
Slide 39 text
Not Mentioned…
Priority
Content Resistance
Content Hugging
Animation
Layout Debugging
Slide 40
Slide 40 text
Q & A
Slide 41
Slide 41 text
Reference
Apple Developer Library - Auto
Layout Guide
https:/
/developer.apple.com/
library/ios/documentation/
userexperience/conceptual/
AutolayoutPG/Introduction/
Introduction.html