Post on 15-May-2015
What's On For Today?
1.Theming Applications
2.Introducing UIAppearance
3.Example
How do you "theme" your application with color, style?
Common UI Customizations
– UINavigationBar tint color, title image
– UIToolbar tint color
– UIBarButtonItem tint color, style
– UIButton, UILabel, etc.
Pre-iOS5, How Did We Customize?
– viewWillAppear:
– Subclassing UIKit classes' drawRect: method
– NSNotificationCenter
Pre-iOS5, How Did We Customize?
-(void)viewWillAppear:(BOOL)animated:{ [super viewWillAppear:animated]; // What is our current theme? NSUserDefaults *settings = [NSUserDefaults standardUserDefaults]; NSString *theme = [settings objectForKey:@"theme"];
// Set up color based on theme if ([theme isEqualToString:@"red"]) { self.navBar.tintColor = [UIColor redColor]; } else { self.navBar.tintColor = [UIColor blueColor]; }}
The Problem With All Of This
• Every view controller needs to "know" about how to handle themes/styles
• Lots of copy & pasted code, annoying to maintain or add themes
Swinburne University of Technology
What's On For Today?
1. Theming Applications
2. Introducing UIAppearance
3. Example
Without UIAppearance
UINavigationBar
UINavigationBar
UINavigationBar
UIViewController
UIViewController
UIViewController
setTintColor:
setTintColor:
setTintColor:
With UIAppearance, 1
UINavigationBar
UINavigationBar
UINavigationBar
ThemeManager
setTintColor:
UIAppearance Proxy
setTintColor:
With UIAppearance, 2
UIAppearance Proxy
UIViewController
-tintColor:UINavigationBar
alloc/init
Current UIAppearance classes
– UIActivityIndicatorView– UIBarButtonItem– UIBarItem– UINavigationBar– UIProgressView– UISearchBar– UISegmentedControl– UISlider– UISwitch– UITabBar– UITabBarItem– UIToolbar
Source: http://stackoverflow.com/questions/9424112/what-properties-can-i-set-via-an-uiappearance-proxy
More details…
• Unfortunately, Apple hasn't documented this feature well yet.
• Unfortunately, not all UIView subclasses work yet
• Search for UI_APPEARANCE_SELECTOR in Spotlight
• Full reverse-engineered list here: http://www.raywenderlich.com/4344/user-interface-customization-in-ios-5
Who is missing?
• UITableViewCell• UITextField• UILabel
What's On For Today?
1.Theming Applications
2.Introducing UIAppearance
3.Example
THANK YOU
Questions?