itt 2015 - dimitri dupuis-latour - mastering interface builder

61
Mastering Interface Builder — Or how to stop cursing and love IB — Dimitri Dupuis-Latour — @dupuislatour

Upload: istanbul-tech-talks

Post on 13-Jan-2017

299 views

Category:

Engineering


3 download

TRANSCRIPT

Page 1: ITT 2015 - Dimitri Dupuis-Latour - Mastering Interface Builder

Mastering Interface Builder— Or how to stop cursing and love IB —

Dimitri Dupuis-Latour — @dupuislatour

Page 2: ITT 2015 - Dimitri Dupuis-Latour - Mastering Interface Builder

Once Upon a TimeA brief History of IB

Page 3: ITT 2015 - Dimitri Dupuis-Latour - Mastering Interface Builder

Interface Builder1986

Page 4: ITT 2015 - Dimitri Dupuis-Latour - Mastering Interface Builder

IB History A Brief Story of Time…

2001

Mac OS X

1986

NeXT

2008

iPhone SDK

Page 5: ITT 2015 - Dimitri Dupuis-Latour - Mastering Interface Builder

Modern IB History A Dramatic Acceleration of Features

2011iOS 5

AutoLayout(OSX)Storyboards

Segue

2010iOS 4

Xcode IntegrationAll-in-one window

2014iOS 8

IBDesignableIBInspectableSize ClassesCustom FontsLocalisation

2013iOS 7

New AutoLayoutiOS7 makeoverAsset Catalogs

2012iOS 6

AutoLayout(iOS)

Page 6: ITT 2015 - Dimitri Dupuis-Latour - Mastering Interface Builder

Don’t use IB like your Grandfather ! It’s 2015

Page 7: ITT 2015 - Dimitri Dupuis-Latour - Mastering Interface Builder

AgendaStoryboards

TableView ControllersStatic TableViews

Unwind SegueCustom Segue Icon Font

Vector artworkSecret shortcuts

Page 8: ITT 2015 - Dimitri Dupuis-Latour - Mastering Interface Builder

StoryboardsMore than just a meta XIB

Page 9: ITT 2015 - Dimitri Dupuis-Latour - Mastering Interface Builder

Storyboard

Page 10: ITT 2015 - Dimitri Dupuis-Latour - Mastering Interface Builder

Storyboard• Bird’s eye view • Visual way describe workflow • Communication Tool • Living Documentation

Page 11: ITT 2015 - Dimitri Dupuis-Latour - Mastering Interface Builder

Not Approved

Page 12: ITT 2015 - Dimitri Dupuis-Latour - Mastering Interface Builder

• Split by Feature / Tab / Unit of workflow (eg: Login, Creation)

Split Your Storyboards ! No « One Storyboard to Rule Them All »

// STORYBOARD - Instantiate from code let storyboard = UIStoryboard(name:"LoginScreens", bundle:nil) let vc = storyboard.instantiateViewControllerWithIdentifier("MyCustomVC")

as MyCustomVC

Page 13: ITT 2015 - Dimitri Dupuis-Latour - Mastering Interface Builder

• Chain your screens in IB

• Takes out the simpler .push() .presentViewController(), didSelectRowAtIndexPath()

• Handle the more complex ones in - prepareForSegue: (iOS) - contextForSegue: (WatchKit, iOS 9 ?)

Build Navigation Hierarchy in IB

Page 14: ITT 2015 - Dimitri Dupuis-Latour - Mastering Interface Builder

• Design / communication tool

• Split them

• Removes some push() / present() code

• best feature…

Storyboards : Recap More than just a meta XIB

Page 15: ITT 2015 - Dimitri Dupuis-Latour - Mastering Interface Builder

TableView ControllerMore than just a TableView + a Controller

Page 16: ITT 2015 - Dimitri Dupuis-Latour - Mastering Interface Builder

• TableView Controllers = awesome

• TableView Controllers + Storyboard = Even Better !

TableView Controller

Page 17: ITT 2015 - Dimitri Dupuis-Latour - Mastering Interface Builder

• Common setup for free: .delegate, .datasource, autoresizingMasks, editButton…

• Design your cell directly in the tableViewNo more extra xib just for a cell No more registerCell / registerClass

• Pull-to-Refresh for (almost) free

• Keyboard handling for free:Textfield at bottom of a form : will scroll up automagically

TableViewController Whether in a XIB or Storyboard

Page 18: ITT 2015 - Dimitri Dupuis-Latour - Mastering Interface Builder

• Table-View like layoutwith known number of items

• Good examples:- Settings Screen- Detail View of a List View

Static TableView Cells Only within a Storyboard

Page 19: ITT 2015 - Dimitri Dupuis-Latour - Mastering Interface Builder

Static TableView Cells Only within a Storyboard

Page 20: ITT 2015 - Dimitri Dupuis-Latour - Mastering Interface Builder

• No dequeing

• No delegate to implement

• Directly set the number of cells & sections header/footer section title, etc…

• Outlet directly to a cell or a cell subview

• Mix static and dynamic cellsImplement delegates and call [super ] for static rows

Static TableView Cells Only within a Storyboard

Page 21: ITT 2015 - Dimitri Dupuis-Latour - Mastering Interface Builder

Unwind SeguePush-pop-dismiss : sooo 2011

Page 22: ITT 2015 - Dimitri Dupuis-Latour - Mastering Interface Builder

What are Unwind Segue ?

Auto-rewind to a specific screen

Page 23: ITT 2015 - Dimitri Dupuis-Latour - Mastering Interface Builder

A B C D

E F GSubmit

navController.pop().pop() presentingController.dismiss() presentingController.navController.pop().pop().pop()

Problem 1: hardcoding Hierarchy in code

Page 24: ITT 2015 - Dimitri Dupuis-Latour - Mastering Interface Builder

=> write custom @protocols => Store global variable / Singleton

Problem 2: passing data back to A

A B C D

E F GSubmit

Page 25: ITT 2015 - Dimitri Dupuis-Latour - Mastering Interface Builder

A B C D

E F GSubmit

@IBAction func unwindTo### @IBAction func unwindToMyScreenA(segue: UIStoryboardSegue) {}

Step 1

Page 26: ITT 2015 - Dimitri Dupuis-Latour - Mastering Interface Builder

A B C D

E F GSubmit

a) manually (eg: immediate action) b) programmatically (eg: deferred action)Step 2

@IBAction func unwindToMyScreenA(segue: UIStoryboardSegue) {}

Page 27: ITT 2015 - Dimitri Dupuis-Latour - Mastering Interface Builder

A B C D

E F GSubmit

Step 2a - Manually

@IBAction func unwindToMyScreenA(segue: UIStoryboardSegue) {}

Page 28: ITT 2015 - Dimitri Dupuis-Latour - Mastering Interface Builder

• Create a manual segue • ctrl-drag from File's Owner (VC) to Exit • choose Manual Segue • Select it in the outline view • Give it an Identifier "backToAPlease"

• Call it from Code

Step 2b - Programmatically

self.performSegueWithIdentifier("backToAPlease", sender:nil)

File's Owner Exit

Page 29: ITT 2015 - Dimitri Dupuis-Latour - Mastering Interface Builder

• "Unwind" the navigation stack

• Including through push, modal, popover, tabs, etc…

• Passes data back (replacing custom @protocols)

• Less code

Unwind Segue : Recap

Page 30: ITT 2015 - Dimitri Dupuis-Latour - Mastering Interface Builder

Custom SegueGo beyond push and modal

Page 31: ITT 2015 - Dimitri Dupuis-Latour - Mastering Interface Builder

• Step 1) Select • Step 2) Set your class • Step 3) Enjoy !

Setup a Custom Segue

Page 32: ITT 2015 - Dimitri Dupuis-Latour - Mastering Interface Builder

3DFlip Seguegithub.com/GlennChiu/

GC3DFlipTransitionStyleSegue

Page 33: ITT 2015 - Dimitri Dupuis-Latour - Mastering Interface Builder

Fold Seguehttps://github.com/mpospese/

MPFoldTransition

Page 34: ITT 2015 - Dimitri Dupuis-Latour - Mastering Interface Builder

DoorwaySeguegithub.com/jsmecham/DoorwaySegue

Page 35: ITT 2015 - Dimitri Dupuis-Latour - Mastering Interface Builder

• Create your own transitions by subclassing UIStoryBoardSegue

• Componentize transistions in reusable blocks

• Share and reuse them !

Custom Segue : Recap Go beyond push & pop

Page 36: ITT 2015 - Dimitri Dupuis-Latour - Mastering Interface Builder

Icon FontVector artwork, everywhere

Page 37: ITT 2015 - Dimitri Dupuis-Latour - Mastering Interface Builder

Stop Using PNGs, Start using Vector Icons

with Icon Fonts

Page 38: ITT 2015 - Dimitri Dupuis-Latour - Mastering Interface Builder

FontAwesome479 icons. 86 Ko.

Page 39: ITT 2015 - Dimitri Dupuis-Latour - Mastering Interface Builder

IonIcon733 icons. 180 Ko. iOS7 style

Page 40: ITT 2015 - Dimitri Dupuis-Latour - Mastering Interface Builder

Google Material Design

Page 41: ITT 2015 - Dimitri Dupuis-Latour - Mastering Interface Builder

Custom FontMake Your Own !

Page 42: ITT 2015 - Dimitri Dupuis-Latour - Mastering Interface Builder

• Vector !

• Light

• Change color, size, state, shadows… on the fly

• Works on the Web & Android too !

• No need for 3 resolutions for each icon

Advantages

Page 43: ITT 2015 - Dimitri Dupuis-Latour - Mastering Interface Builder

Resolution Hell

RetinaRetina HD

Normal

Page 44: ITT 2015 - Dimitri Dupuis-Latour - Mastering Interface Builder

Android : 2 more sizes !

Page 45: ITT 2015 - Dimitri Dupuis-Latour - Mastering Interface Builder

Handle all color, size, state

! Record

! Recording…

! recorded: Today, 7:00pmEnregistrement #1 "

! recorded: Today, 7:00pmEnregistrement #1 "

!

2x

!

!

!

!

3x

!

!

!

!

1x

!

!

!

Page 46: ITT 2015 - Dimitri Dupuis-Latour - Mastering Interface Builder

• Use directly • in IB • in Code (NSAttributedString)

• Use a helper framework : • FontAwesomeKit (iOS) • Iconify (Android)

Helper Frameworks

New in Interface Builder 6

Page 47: ITT 2015 - Dimitri Dupuis-Latour - Mastering Interface Builder

• iOS library to ease FontAwesome Integration

• pod ‘FontAwesomeKit’

• Create / Modify / Stack icons from code

• Generates UIImage or NSAttributedString

• Bundles 4 popular Icon Fonts (1594 icons, 380Ko)

FontAwesomeKit github.com/PrideChung/FontAwesomeKit

Page 48: ITT 2015 - Dimitri Dupuis-Latour - Mastering Interface Builder

Example: Attributed Text

Nom Prénom

# Paris, France⋆ ⋆ ⋆ ⋆ ⋆ 10 reviews&

Page 49: ITT 2015 - Dimitri Dupuis-Latour - Mastering Interface Builder

@IBOutlet private weak var locationLabel: UILabel!

// …

let icon = FAKFontAwesome.locationArrowIconWithSize(30) locationLabel.attributedText = icon.attributedString()

Example: Attributed TextNom Prénom

# Paris, France⋆ ⋆ ⋆ ⋆ ⋆ 4,5&

Page 50: ITT 2015 - Dimitri Dupuis-Latour - Mastering Interface Builder

@IBOutlet private weak var userPicture: UIImageView!

// …

let icon = FAKFontAwesome.userIconWithSize(30) icon.addAttribute(NSForegroundColorAttributeName, value:UIColor.lightGrayColor())

userPicture.image = icon.imageWithSize(CGSize(width: 44, height: 44)) userPicture.layer.borderColor = UIColor.darkGrayColor().CGColor userPicture.layer.borderWidth = 1 userPicture.layer.cornerRadius = 22

Example: User Picture Placeholder

Nom Prénom# Paris 9ème⋆ ⋆ ⋆ ⋆ ⋆ 4,5&

Page 51: ITT 2015 - Dimitri Dupuis-Latour - Mastering Interface Builder

Example: Stacked Icons

// No Photos please ! let icons = [ FAKFontAwesome.photoIconWithSize(30), FAKFontAwesome.banIconWithSize(30) ]

let noPhotosPlease = UIImage(stackedIcons:icons, imageSize:CGSizeMake(30, 30))

Page 52: ITT 2015 - Dimitri Dupuis-Latour - Mastering Interface Builder

• Great to centralize your assets, across your properties (website, iOS app, android app)

• Desktop Tools (Glyphs.app, FontLab…)

• Online Tools (icomoon.io, prototypo.io…)

• Check thenounproject.com

Creating your own Font Icons

Page 53: ITT 2015 - Dimitri Dupuis-Latour - Mastering Interface Builder

The Noun Project Google Image for Icons

Page 54: ITT 2015 - Dimitri Dupuis-Latour - Mastering Interface Builder

— Joan Zapata, Creator of Iconify Library

« If, like me, you're tired of copying 3 images (@1x, @2x, @3x) for each icon you want to use in your app, for each color you

want to use them with, and bang your head on the wall when you suddenly need to change their color or size, then I think

Icon Font can help you. »

Icon Fonts: One-sentence Summary

Page 55: ITT 2015 - Dimitri Dupuis-Latour - Mastering Interface Builder

One More ThingKeybord Shortcuts

Page 56: ITT 2015 - Dimitri Dupuis-Latour - Mastering Interface Builder

Click Through Views

+ctrl + click⏏ shift

Page 57: ITT 2015 - Dimitri Dupuis-Latour - Mastering Interface Builder

Measure distances

⌥alt + mouse over

Page 58: ITT 2015 - Dimitri Dupuis-Latour - Mastering Interface Builder

! Insert Emoji " Or any symbol really©�✔

+ctrl + space⌘ cmd

println("⛔ Found Error: ") println("⚠ Warning: ") println("✅ All Good: ")

Page 59: ITT 2015 - Dimitri Dupuis-Latour - Mastering Interface Builder

RecapStoryboards

TableView ControllersStatic TableViews

Unwind SegueCustom Segue Icon Font

Vector artworkSecret shortcuts

Page 60: ITT 2015 - Dimitri Dupuis-Latour - Mastering Interface Builder
Page 61: ITT 2015 - Dimitri Dupuis-Latour - Mastering Interface Builder

Dimitri Dupuis-Latour ' @dupuislatour

Thank You !