A tutorial worksheet on Autolayout made for the Mobile Developers of Berkeley Training program.
It covers
- Using Interface Builder (IB) to set constraints
- Settings constraints programmatically
- Writing constraints to handle different size classes
- Writing constraints to allow rotation
- Stack Views
On the master branch, all storyboard view controllers are empty, and the StoryboardViewController and AutoLayoutViewController are unimplemented.
To fill in the worksheet
- Build the UI for the
AutoLayoutViewControllerprogrammatically usingNSLayoutConstraintandUIStackView.- Use
traitCollectionsto handle rotation
- Use
- Use Interface Builder (IB) to build the view for
StoryboardViewController- Use constraint customizations to handle rotation for iPhones
- Use IBOutlet and IBAction to hook up the
UILabelandUIButtonto work properly- The
UIButtonshould change the text of theUILabelto say "Hello"
- The
Solutions to the worksheet can be found on the solutions branch
- Don't forget to use
view.safeAreaLayoutGuide - If XCode is telling you that your constraints are ambiguous, that means you don't have enough of them
- XCode can suggest constraints to you
- Remember the priority property of
NSLayoutConstraint - Don't forget to set
translatesAutoresizingMaskIntoConstraintstofalsefor each programmatic view

