Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Intermediate Auto Layout

7ac1ab5bb2ef53dea57f36dd24e3b3c0?s=47 Peter Stuart
December 12, 2013

Intermediate Auto Layout

Talk given at CocoaHeads Boston.

7ac1ab5bb2ef53dea57f36dd24e3b3c0?s=128

Peter Stuart

December 12, 2013
Tweet

Transcript

  1. Intermediate
 Auto Layout

  2. Layout Guides

  3. Layout Guides id topLayoutGuide = self.topLayoutGuide; NSDictionary *views = NSDictionaryOfVariableBindings(topLayoutGuide,

    someView); ... @"V:[topLayoutGuide]-[someView]" ...
  4. Scroll Views

  5. Scroll Views

  6. Scroll Views [NSLayoutConstraint
 constraintWithItem:container
 attribute:NSLayoutAttributeWidth
 relatedBy:NSLayoutRelationEqual
 toItem:scrollView
 attribute:NSLayoutAttributeWidth
 multiplier:1
 constant:0];

  7. Scroll Views - (void)keyboardWillShow:(NSNotification *)notification { CGFloat offset = ...;

    self.bottomConstraint.constant = offset; [UIView animate...:^{ [self.view layoutIfNeeded]; }]; }
  8. Custom Views • Should know their intrinsic size • constraints

    • intrinsicContentSize
  9. Custom Views • Should know how to be laid out

    • alignmentRectInsets
  10. Custom Views return UIEdgeInsetsMake(25, 0, 0, 25); 1

  11. Compression Resistance This is some pretty long text. Low High

    High
  12. Compression Resistance This is some … Low High High

  13. Compression Resistance [view setContentCompressionResistancePriority:UILayoutPriorityDefaultLow forOrientation:UILayoutConstraintOrientationHorizontal];

  14. Hugging Text Text Low High High Text

  15. Hugging Text Text Low High High Text

  16. Hugging [view setContentHuggingPriority:UILayoutPriorityDefaultLow forOrientation:UILayoutConstraintOrientationHorizontal] ;

  17. Misc. • Align views/controls that contain text using NSLayoutAttributeBaseline, not

    NSLayoutAttributeCenterY • Manage constraints with views, not view controllers • Avoid using explicit sizes