IBDesignable - CocoaConf Seattle 2014

Post on 12-Jul-2015

350 views 1 download

Tags:

Transcript of IBDesignable - CocoaConf Seattle 2014

Instant Gratificationin Interface Builder

Making Views

Where’s the subview?

See Constraints

Show Bounds

Playgrounds

IBDesignable

See your view live in Interface Builder

Tweak your view live in Interface Builder

What’s in it for me?

DRY

DRY

(Insert Seattle joke here)

DRY

(Insert Seattle joke here)

MVC

MVC

⌘-R

self.borderWidth = 10;

Build & Run. Get to screen.

Observe Cool UI.

self.borderWidth = 20;

Build & Run. Get to screen.

Observe Cool UI.

self.borderWidth = 15;

Build & Run. Get to screen.

Observe Cool UI.

Repeat

Repeat ad nauseam

Case Study

All Places

Single Place

Single PlaceAll Places

Place Map

Practical Application

From Zero to VisibleDemo

IBInspectable

IBInspectable Properties• Boolean

• Integer / Float

• String / Localized String

• CGRect CGPoint CGSize

• Color

• Range

• Nil

Update LiveDemo

Problems

Problems and Solutions

NSFont・UIFont

Debugging / Logging

public func liveDebugLog(message: String) { #if !(TARGET_OS_IPHONE) // ENSURE LOG FILE EXISTS let logPath = "/tmp/XcodeLiveRendering.log" let fm = NSFileManager.createIfNecessary(logPath) // GET FILE HANDLE var fileHandle = NSFileHandle(forWritingAtPath: logPath)! fileHandle.seekToEndOfFile() // WRITE OUT LOG let data = message.asUTF8Data fileHandle.writeData(data)

#endif

}

CocoaPods

$ gem update cocoapods

# build for all architectures post_install do |installer| installer.project.targets.each do |target| target.build_configurations.each do |config| config.build_settings['ONLY_ACTIVE_ARCH'] = 'NO' end end end

Can’t drag and drop from subview UIControls to

create IBActions

videoControlsView?.playButton.addTarget(self,

action: Selector("tappedPlayButton"),

forControlEvents: UIControlEvents.TouchUpInside)

Use Target-Action

IBInspectable properties of subviews aren’t

exposed.

Preemptive Q&A

Do I have to use a separate framework?

No

Does this work in Objective-C?

Yes

Can I do my view layout in Interface Builder?

Probably

http://justabeech.com/2014/07/27/xcode-6-live-rendering-from-nib/

Resources

Debugging

Using Assets

Apple Docs

https://developer.apple.com/library/ios/recipes/xcode_help-IB_objects_media/chapters/

CreatingaLiveViewofaCustomObject.html

@MartinJNash Seattle