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

How To Achieve Auto Layout Zen

How To Achieve Auto Layout Zen

A step-by-step guide to getting the best out of Cocoa Auto Layout with Interface Builder.

Demo Code: https://github.com/followben/autolayout-zen

First presented at CocoaHeads BNE on Tuesday 7th May, 2013.

Ben Stovold

May 07, 2013
Tweet

More Decks by Ben Stovold

Other Decks in Programming

Transcript

  1. Hi

  2. “I hope to phase out IB as I transition to

    using auto layout.” - Michael Tsai
  3. = The Future Auto Layout + Interface Builder Subscripting Dot

    Syntax Storyboards Embed Segues ARC Core Data Singletons
  4. The Right Tool For the Right Job + (id)constraintWithItem:(id)view1 attribute:(NSLayoutAttribute)attr1

    relatedBy:(NSLayoutRelation)relation toItem:(id)view2 attribute:(NSLayoutAttribute)attr2 multiplier:(CGFloat)multiplier constant:(CGFloat)c + (NSArray *)constraintsWithVisualFormat:(NSString *)format options:(NSLayoutFormatOptions)opts metrics:(NSDictionary *)metrics views:(NSDictionary *)views
  5. @interface UIView (Autolayout) +(id)autolayoutView; @end @implementation UIView (Autolayout) +(id)autolayoutView {

    UIView *view = [self new]; view.translatesAutoresizingMaskIntoConstraints = NO; return view; } @end
  6. @interface UIView (Autolayout) +(id)autolayoutView; @end @implementation UIView (Autolayout) +(id)autolayoutView {

    UIView *view = [self new]; view.translatesAutoresizingMaskIntoConstraints = NO; return view; } @end