Interface Builder Core Concepts - Apple Inc. · These are confidential sessions—please refrain...

64
These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 405 Interface Builder Core Concepts Kelly Keenan Engineer

Transcript of Interface Builder Core Concepts - Apple Inc. · These are confidential sessions—please refrain...

Page 1: Interface Builder Core Concepts - Apple Inc. · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 405 Interface Builder Core Concepts

These are confidential sessions—please refrain from streaming, blogging, or taking pictures

Session 405

Interface Builder Core Concepts

Kelly KeenanEngineer

Page 2: Interface Builder Core Concepts - Apple Inc. · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 405 Interface Builder Core Concepts

Introduction

Page 3: Interface Builder Core Concepts - Apple Inc. · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 405 Interface Builder Core Concepts

Introduction

Page 4: Interface Builder Core Concepts - Apple Inc. · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 405 Interface Builder Core Concepts

“We build interfaces by dragging and dropping controls and views, configuring properties, and

making connections.”

Page 5: Interface Builder Core Concepts - Apple Inc. · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 405 Interface Builder Core Concepts

! float insetFromEdge = 10.0;! float sizeAdjustment = insetFromEdge * 2;!! UIImage * buttonImage = [UIImage imageNamed:@"info.png"];! CGRect buttonFrame = CGRectMake(applicationFrame.size.width-40, applicationFrame.size.height-40, buttonImage.size.width + sizeAdjustment, buttonImage.size.height + sizeAdjustment);!UIButton * infoButton = [[UIButton alloc] initWithFrame:buttonFrame];! infoButton.contentEdgeInsets = UIEdgeInsetsMake(insetFromEdge, insetFromEdge, insetFromEdge, insetFromEdge);! infoButton.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;! infoButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;![infoButton setImage:buttonImage forState:UIControlStateNormal];! infoButton.adjustsImageWhenHighlighted = YES;![infoButton addTarget:self action:@selector(toggleView:) forControlEvents:UIControlEventTouchUpInside];

! [mainView addSubview:infoButton];! [infoButton release];! !

Change colors to match template - make code throughout the box transparent and show after transition behind large white text

Page 6: Interface Builder Core Concepts - Apple Inc. · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 405 Interface Builder Core Concepts

! float insetFromEdge = 10.0;! float sizeAdjustment = insetFromEdge * 2;!! UIImage * buttonImage = [UIImage imageNamed:@"info.png"];! CGRect buttonFrame = CGRectMake(applicationFrame.size.width-40, applicationFrame.size.height-40, buttonImage.size.width + sizeAdjustment, buttonImage.size.height + sizeAdjustment);!UIButton * infoButton = [[UIButton alloc] initWithFrame:buttonFrame];! infoButton.contentEdgeInsets = UIEdgeInsetsMake(insetFromEdge, insetFromEdge, insetFromEdge, insetFromEdge);! infoButton.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;! infoButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;![infoButton setImage:buttonImage forState:UIControlStateNormal];! infoButton.adjustsImageWhenHighlighted = YES;![infoButton addTarget:self action:@selector(toggleView:) forControlEvents:UIControlEventTouchUpInside];

! [mainView addSubview:infoButton];! [infoButton release];! !Add Button to Window

Set Button Target and Action

Add Image to Button

Create Button

Create ImageChange colors to match template - make code throughout the box transparent and show after transition behind large white text

Page 7: Interface Builder Core Concepts - Apple Inc. · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 405 Interface Builder Core Concepts
Page 8: Interface Builder Core Concepts - Apple Inc. · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 405 Interface Builder Core Concepts

Info Button

Page 9: Interface Builder Core Concepts - Apple Inc. · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 405 Interface Builder Core Concepts
Page 10: Interface Builder Core Concepts - Apple Inc. · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 405 Interface Builder Core Concepts

Canvas

Page 11: Interface Builder Core Concepts - Apple Inc. · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 405 Interface Builder Core Concepts

Document Outline

Page 12: Interface Builder Core Concepts - Apple Inc. · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 405 Interface Builder Core Concepts

Inspectors

Page 13: Interface Builder Core Concepts - Apple Inc. · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 405 Interface Builder Core Concepts

Library

Page 14: Interface Builder Core Concepts - Apple Inc. · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 405 Interface Builder Core Concepts

View

Controller

Model

MVCRelate interface elements to code

Page 15: Interface Builder Core Concepts - Apple Inc. · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 405 Interface Builder Core Concepts

ViewView

Controller

Model

MVCRelate interface elements to code

Page 16: Interface Builder Core Concepts - Apple Inc. · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 405 Interface Builder Core Concepts

View

Controller

View

Controller

Model

MVCRelate interface elements to code

Page 17: Interface Builder Core Concepts - Apple Inc. · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 405 Interface Builder Core Concepts

View

Controller

View

Controller

Model

MVCRelate interface elements to code

Page 18: Interface Builder Core Concepts - Apple Inc. · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 405 Interface Builder Core Concepts

Storyboards

Page 19: Interface Builder Core Concepts - Apple Inc. · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 405 Interface Builder Core Concepts

Scenes

•A screen or portionof the user interface

Page 20: Interface Builder Core Concepts - Apple Inc. · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 405 Interface Builder Core Concepts

Scenes

•A screen or portionof the user interface

Page 21: Interface Builder Core Concepts - Apple Inc. · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 405 Interface Builder Core Concepts

Segue

• The action to move from one scene to another• Push data from one scene to the next

Page 22: Interface Builder Core Concepts - Apple Inc. · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 405 Interface Builder Core Concepts

Segue

• The action to move from one scene to another• Push data from one scene to the next

Page 23: Interface Builder Core Concepts - Apple Inc. · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 405 Interface Builder Core Concepts

Demo applicationJogr

• Create simple user interfaces• Change properties• Resize and align objects•Make connections

■ Between scenes■ To code

Page 24: Interface Builder Core Concepts - Apple Inc. · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 405 Interface Builder Core Concepts

Demo applicationJogr

• Create simple user interfaces• Change properties• Resize and align objects•Make connections

■ Between scenes■ To code

Page 25: Interface Builder Core Concepts - Apple Inc. · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 405 Interface Builder Core Concepts

DemoBuilding an interface

Page 26: Interface Builder Core Concepts - Apple Inc. · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 405 Interface Builder Core Concepts

UIButton *pauseRunButton;@property (weak, nonatomic)

OutletsConnect UI objects to properties

Page 27: Interface Builder Core Concepts - Apple Inc. · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 405 Interface Builder Core Concepts

UIButton *pauseRunButton;IBOutlet@property (weak, nonatomic)

OutletsConnect UI objects to properties

Page 28: Interface Builder Core Concepts - Apple Inc. · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 405 Interface Builder Core Concepts

pauseOrRun:(id)sender;- (void)

ActionsConnect controls to methods

Page 29: Interface Builder Core Concepts - Apple Inc. · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 405 Interface Builder Core Concepts

pauseOrRun:(id)sender;- (IBAction)

ActionsConnect controls to methods

Page 30: Interface Builder Core Concepts - Apple Inc. · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 405 Interface Builder Core Concepts

Storyboards. . .What’s Next?

Alex Raftis

Page 31: Interface Builder Core Concepts - Apple Inc. · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 405 Interface Builder Core Concepts

Transferring Data

Page 32: Interface Builder Core Concepts - Apple Inc. · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 405 Interface Builder Core Concepts

Transferring Data

Page 33: Interface Builder Core Concepts - Apple Inc. · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 405 Interface Builder Core Concepts

Transferring Data

Page 34: Interface Builder Core Concepts - Apple Inc. · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 405 Interface Builder Core Concepts

Transferring Data

Page 35: Interface Builder Core Concepts - Apple Inc. · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 405 Interface Builder Core Concepts

Demo applicationJogr

•Gesture recognizer•Activating segues in code• Passing data between scenes• Setting delegates and data sources• Create reusable table cells•Adding custom UI elements

Page 36: Interface Builder Core Concepts - Apple Inc. · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 405 Interface Builder Core Concepts

Demo applicationJogr

•Gesture recognizer•Activating segues in code• Passing data between scenes• Setting delegates and data sources• Create reusable table cells•Adding custom UI elements

Page 37: Interface Builder Core Concepts - Apple Inc. · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 405 Interface Builder Core Concepts

Demo applicationJogr

•Gesture recognizer•Activating segues in code• Passing data between scenes• Setting delegates and data sources• Create reusable table cells•Adding custom UI elements

Page 38: Interface Builder Core Concepts - Apple Inc. · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 405 Interface Builder Core Concepts

Demo applicationJogr

•Gesture recognizer•Activating segues in code• Passing data between scenes• Setting delegates and data sources• Create reusable table cells•Adding custom UI elements

Page 39: Interface Builder Core Concepts - Apple Inc. · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 405 Interface Builder Core Concepts

DemoStoryboards. . .what’s next?

Page 40: Interface Builder Core Concepts - Apple Inc. · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 405 Interface Builder Core Concepts

UIViewControllerView Controllers and Segues

Page 41: Interface Builder Core Concepts - Apple Inc. · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 405 Interface Builder Core Concepts

UIViewControllerView Controllers and Segues

storyboard (property)

Page 42: Interface Builder Core Concepts - Apple Inc. · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 405 Interface Builder Core Concepts

UIViewControllerView Controllers and Segues

storyboard (property)•The storyboard from the originating view controller

Page 43: Interface Builder Core Concepts - Apple Inc. · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 405 Interface Builder Core Concepts

UIViewControllerView Controllers and Segues

storyboard (property)•The storyboard from the originating view controller

-performSegueWithIdentifier:sender:

Page 44: Interface Builder Core Concepts - Apple Inc. · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 405 Interface Builder Core Concepts

UIViewControllerView Controllers and Segues

storyboard (property)•The storyboard from the originating view controller

-performSegueWithIdentifier:sender:• Initiates the segue with the specified identifier from the view controller’s storyboard file

Page 45: Interface Builder Core Concepts - Apple Inc. · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 405 Interface Builder Core Concepts

UIViewControllerView Controllers and Segues

storyboard (property)•The storyboard from the originating view controller

-performSegueWithIdentifier:sender:• Initiates the segue with the specified identifier from the view controller’s storyboard file

-prepareForSegue:sender:

Page 46: Interface Builder Core Concepts - Apple Inc. · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 405 Interface Builder Core Concepts

UIViewControllerView Controllers and Segues

storyboard (property)•The storyboard from the originating view controller

-performSegueWithIdentifier:sender:• Initiates the segue with the specified identifier from the view controller’s storyboard file

-prepareForSegue:sender:•Notifies the view controller that a segue is about to be performed

Page 47: Interface Builder Core Concepts - Apple Inc. · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 405 Interface Builder Core Concepts
Page 48: Interface Builder Core Concepts - Apple Inc. · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 405 Interface Builder Core Concepts
Page 49: Interface Builder Core Concepts - Apple Inc. · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 405 Interface Builder Core Concepts
Page 50: Interface Builder Core Concepts - Apple Inc. · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 405 Interface Builder Core Concepts

UIStoryboardInstantiating Storyboards

Page 51: Interface Builder Core Concepts - Apple Inc. · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 405 Interface Builder Core Concepts

UIStoryboardInstantiating Storyboards

+storyboardWithName:bundle:

Page 52: Interface Builder Core Concepts - Apple Inc. · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 405 Interface Builder Core Concepts

UIStoryboardInstantiating Storyboards

+storyboardWithName:bundle:•Creates and returns a storyboard object

Page 53: Interface Builder Core Concepts - Apple Inc. · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 405 Interface Builder Core Concepts

UIStoryboardInstantiating Storyboards

+storyboardWithName:bundle:•Creates and returns a storyboard object

-instantiateInitialViewController

Page 54: Interface Builder Core Concepts - Apple Inc. · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 405 Interface Builder Core Concepts

UIStoryboardInstantiating Storyboards

+storyboardWithName:bundle:•Creates and returns a storyboard object

-instantiateInitialViewController• Instantiates and returns the initial view controller

Page 55: Interface Builder Core Concepts - Apple Inc. · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 405 Interface Builder Core Concepts

UIStoryboardInstantiating Storyboards

+storyboardWithName:bundle:•Creates and returns a storyboard object

-instantiateInitialViewController• Instantiates and returns the initial view controller

-instantiateViewControllerWithIdentifier:

Page 56: Interface Builder Core Concepts - Apple Inc. · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 405 Interface Builder Core Concepts

UIStoryboardInstantiating Storyboards

+storyboardWithName:bundle:•Creates and returns a storyboard object

-instantiateInitialViewController• Instantiates and returns the initial view controller

-instantiateViewControllerWithIdentifier:• Instantiates and returns the initial viewcontroller with the specified identifier

Page 57: Interface Builder Core Concepts - Apple Inc. · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 405 Interface Builder Core Concepts

XIB Files

Page 58: Interface Builder Core Concepts - Apple Inc. · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 405 Interface Builder Core Concepts

NSNib and UINib

• Load nibs from disk once• Instantiate nibs from memory •Minimizes overhead

Page 59: Interface Builder Core Concepts - Apple Inc. · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 405 Interface Builder Core Concepts

NSNib and UINib

• Load nibs from disk once• Instantiate nibs from memory •Minimizes overhead

Name of FruitImage

Name of FruitImage

Name of FruitImage

Name of FruitImage

Name of FruitImage

Name of FruitImage

Name of FruitImage

Apple

Pear

Cherry

Strawberry

Pineapple

Orange

Lemon

Page 60: Interface Builder Core Concepts - Apple Inc. · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 405 Interface Builder Core Concepts

More Information

Dave DeLongApp Frameworks and Developer Tools [email protected]

DocumentationMac OS X Human Interface Guidelineshttp://developer.apple.com/ue

Interface Builder Helphttps://developer.apple.com/library/ios/#recipes/xcode_help-interface_builder/_index.html

Apple Developer Forumshttp://devforums.apple.com

Page 61: Interface Builder Core Concepts - Apple Inc. · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 405 Interface Builder Core Concepts

Taking Control of Auto Layout in Xcode 5 PresidioWednesday 10:15AM

Related Sessions

Xcode Core Concepts MissionTuesday 10:15AM

Page 62: Interface Builder Core Concepts - Apple Inc. · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 405 Interface Builder Core Concepts

Labs

Interface Builder Lab Tools Lab BThursday 9:00AM

Interface Builder Lab Tools Lab BWednesday 2:00PM

Page 63: Interface Builder Core Concepts - Apple Inc. · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 405 Interface Builder Core Concepts

Summary

• Create a simple project•Work with storyboards• Connect actions and outlets• The importance of delegates and data sources•Manually invoke segues• Load storyboards in code

Page 64: Interface Builder Core Concepts - Apple Inc. · These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 405 Interface Builder Core Concepts