Slide 1

Slide 1 text

UI Customization API Karl Bode @karl_in Neu in iOS 5... hot coffee apps

Slide 2

Slide 2 text

• Neue Styling-Properties • UIAppearance • UIAppearanceContainer • Code-Beispiele Übersicht Karl Bode iOS 5 - UI Customization API

Slide 3

Slide 3 text

• Neue Styling-Properties • UIAppearance • UIAppearanceContainer • Code-Beispiele Übersicht Karl Bode iOS 5 - UI Customization API

Slide 4

Slide 4 text

• Neue Styling-Properties • UIAppearance • UIAppearanceContainer • Code-Beispiele Übersicht Karl Bode iOS 5 - UI Customization API

Slide 5

Slide 5 text

TintColor • UIActivityIndicatorView • UIProgressView • UISlider • UISwitch • UISegmentedControl • UI***Bar • UIBarButtonItem Karl Bode iOS 5 - UI Customization API

Slide 6

Slide 6 text

Image • UIBarButtonItem • UINavigationBar • UISearchBar • UITabBar • UIToolbar • UIProgressView • UISegmentedControl Karl Bode iOS 5 - UI Customization API

Slide 7

Slide 7 text

TextAttributes • UIBarItem • UINavigationBar • UISearchBar • UISegmentedControl Karl Bode iOS 5 - UI Customization API [NSDictionary dictionaryWithObjectsAndKeys: [UIColor whiteColor], UITextAttributeTextColor, nil]];

Slide 8

Slide 8 text

PositionAdjustment • UIBarButtonItem • UINavigationBar • UISearchBar • UISegmentedControl Karl Bode iOS 5 - UI Customization API

Slide 9

Slide 9 text

Proxy-Mechanismus [UISwitch appearance]

Slide 10

Slide 10 text

• UIAppearance Protokoll • Klassenmethode: appearance • iOS-Runtime liefert Proxy-Instanz • Styling wird “aufgezeichnet” • Styling wird vor [UIView layoutSubviews] “abgespielt” Proxy-Mechanismus Karl Bode iOS 5 - UI Customization API

Slide 11

Slide 11 text

• kein Styling in Echtzeit, View muss neu aufgebaut werden • funktioniert auch mit Subklassen • direktes Styling wird immer bevorzugt Proxy-Mechanismus Karl Bode iOS 5 - UI Customization API

Slide 12

Slide 12 text

Proxy-Mechanismus ... UISwitch *switchProxy = [UISwitch appearance]; switchProxy.onTintColor = [UIColor greenColor]; ... Alle Instanzen der Klasse UISwitch anpassen: Karl Bode iOS 5 - UI Customization API

Slide 13

Slide 13 text

[self showCode]; Karl Bode iOS 5 - UI Customization API

Slide 14

Slide 14 text

Proxy-Mechanismus ... @interface KBCustomView : UIView @property(nonatomic, retain) UIColor* someColor UI_APPEARANCE_SELECTOR; @end ... Style-Properties werden mit UI_APPEARANCE_SELECTOR markiert: Karl Bode iOS 5 - UI Customization API

Slide 15

Slide 15 text

[self showCode]; Karl Bode iOS 5 - UI Customization API

Slide 16

Slide 16 text

Containment • UIAppearanceContainer als Marker-Protokoll • +[id whenContainedIn: [Class class], nil]; • Statement von unten nach oben schreiben Karl Bode iOS 5 - UI Customization API

Slide 17

Slide 17 text

UIWindow UIView UITabBarViewController UIView KBSecondViewController UIView KBFirstViewController UIView UINavigationController UIView KBNavigationController UISwitch UISwitch Containment-Hierarchie Karl Bode iOS 5 - UI Customization API

Slide 18

Slide 18 text

UIWindow UIView UITabBarViewController UIView KBSecondViewController UIView KBFirstViewController UIView UINavigationController UIView KBNavigationController UISwitch UISwitch Containment-Hierarchie [UISwitch appearance]; Karl Bode iOS 5 - UI Customization API

Slide 19

Slide 19 text

UIWindow UIView UITabBarViewController UIView KBSecondViewController UIView KBFirstViewController UIView UINavigationController UIView KBNavigationController UISwitch UISwitch Containment-Hierarchie Karl Bode iOS 5 - UI Customization API

Slide 20

Slide 20 text

UIWindow UIView UITabBarViewController UIView KBSecondViewController UIView KBFirstViewController UIView UINavigationController UIView KBNavigationController UISwitch UISwitch Containment-Hierarchie [UISwitch appearanceWhenContainedIn:[KBFirstViewController class], nil]]; Karl Bode iOS 5 - UI Customization API

Slide 21

Slide 21 text

UIWindow UIView UITabBarViewController UIView KBSecondViewController UIView KBFirstViewController UIView UINavigationController UIView KBNavigationController UISwitch UISwitch Containment-Hierarchie Karl Bode iOS 5 - UI Customization API

Slide 22

Slide 22 text

UIWindow UIView UITabBarViewController UIView KBSecondViewController UIView KBFirstViewController UIView UINavigationController UIView KBNavigationController UISwitch UISwitch Containment-Hierarchie Karl Bode iOS 5 - UI Customization API [UISwitch appearanceWhenContainedIn: [KBSecondViewController class], [KBNavigationController class], nil]];

Slide 23

Slide 23 text

Containment-Hierarchie • erster eindeutiger Treffer von oben nach unten “gewinnt” • spezieller vor unspezieller • teilweise müssen z.B. leere Klassen als Marker erstellt werden Karl Bode iOS 5 - UI Customization API

Slide 24

Slide 24 text

[self showCode]; Karl Bode iOS 5 - UI Customization API

Slide 25

Slide 25 text

Fazit • neue Properties vereinfachen das Customizing deutlich • reicht für viele einfache Fälle aus • Containment-Statement könnte ausdrucksstärker sein • Statements unbedingt immer wieder testen! Karl Bode iOS 5 - UI Customization API

Slide 26

Slide 26 text

Fragen? Karl Bode iOS 5 - UI Customization API @karl_in [email protected]

Slide 27

Slide 27 text

Quellen • Customizing the Appearance of UIKit Controls, Chris Parker, WWDC ’11 • iOS Reference Documentation Karl Bode iOS 5 - UI Customization API