As CodaFI said, if you use iOS 5 or higher, you already have a theme feature. It works as follows:
Add the <IAppearanceContainer> protocol to the class.
Decorate the property you intend to change with UI_APPEARANCE_SELECTOR . Example:
@interface UINavigationBar: ... <IAppearanceContainer>
@property (nonatomic, retain) UIColor * tintColor UI_APPEARANCE_SELECTOR;
@end
- Change the color for all instances of the class:
[[UINavigationBar appearance] setTintColor: [UIColor redColor]];
The example above is a UINavigationBar , but it will work with any custom class. To view objects already supported in iOS 6.1, check the documentation or run the following commands:
cd /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.1.sdk/System/Library/Frameworks/UIKit.framework/Headers grep -H UI_APPEARANCE_SELECTOR ./* | sed 's/ __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_5_0) UI_APPEARANCE_SELECTOR;//'
Suppose you want modular themes:
- Write a large plist file with all fonts, colors, music, and what not. Each of these files will be a theme.
- Read the file through singleton and set values ββwith lines such as
[x appearance] setWhatever:<plist value>] for each element capable of theme. - If you have instances of the same element that should display different elements, get these images through singleton.
This is more or less a tip from Amita Vyavahara. I said plist instead of xml because they are easier to read. Do not duplicate NIB unless you really need to.
source share