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

UI Appearance Customizing in iOS 5

Avatar for Karl Bode Karl Bode
December 01, 2011

UI Appearance Customizing in iOS 5

Mein Beitrag zur iPhone Developer Conference 2011 in Köln.

Avatar for Karl Bode

Karl Bode

December 01, 2011
Tweet

More Decks by Karl Bode

Other Decks in Technology

Transcript

  1. TintColor • UIActivityIndicatorView • UIProgressView • UISlider • UISwitch •

    UISegmentedControl • UI***Bar • UIBarButtonItem Karl Bode iOS 5 - UI Customization API
  2. Image • UIBarButtonItem • UINavigationBar • UISearchBar • UITabBar •

    UIToolbar • UIProgressView • UISegmentedControl Karl Bode iOS 5 - UI Customization API
  3. TextAttributes • UIBarItem • UINavigationBar • UISearchBar • UISegmentedControl Karl

    Bode iOS 5 - UI Customization API [NSDictionary dictionaryWithObjectsAndKeys: [UIColor whiteColor], UITextAttributeTextColor, nil]];
  4. • 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
  5. • 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
  6. Proxy-Mechanismus ... UISwitch *switchProxy = [UISwitch appearance]; switchProxy.onTintColor = [UIColor

    greenColor]; ... Alle Instanzen der Klasse UISwitch anpassen: Karl Bode iOS 5 - UI Customization API
  7. Proxy-Mechanismus ... @interface KBCustomView : UIView<UIAppearance> @property(nonatomic, retain) UIColor* someColor

    UI_APPEARANCE_SELECTOR; @end ... Style-Properties werden mit UI_APPEARANCE_SELECTOR markiert: Karl Bode iOS 5 - UI Customization API
  8. UIWindow UIView UITabBarViewController UIView KBSecondViewController UIView KBFirstViewController UIView UINavigationController UIView

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

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

    KBNavigationController UISwitch UISwitch Containment-Hierarchie Karl Bode iOS 5 - UI Customization API
  11. 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
  12. UIWindow UIView UITabBarViewController UIView KBSecondViewController UIView KBFirstViewController UIView UINavigationController UIView

    KBNavigationController UISwitch UISwitch Containment-Hierarchie Karl Bode iOS 5 - UI Customization API
  13. 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]];
  14. 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
  15. 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
  16. Quellen • Customizing the Appearance of UIKit Controls, Chris Parker,

    WWDC ’11 • iOS Reference Documentation Karl Bode iOS 5 - UI Customization API