Theme
Support one or more configurable appearance themes.
Installation
Install with CocoaPods by adding the following to your Podfile:
use_frameworks!
pod 'Theme'
Then run:
pod install
Usage
Create a plist for your themes.
Register the plist when your app launches:
import Theme
func application(application: UIApplication, willFinishLaunchingWithOptions launchOptions: [NSObject : AnyObject]?) -> Bool {
let themePath = NSBundle.mainBundle().pathForResource("Theme", ofType: "plist")
let themeDictionary = NSDictionary(contentsOfFile: themePath!)
ThemeController.sharedController.registerThemes(themeDictionary!)
...
}
Set the initial theme when your app launches, and change the theme whenever you choose.
Observe changes to the theme from any view, view controller, or other object:
import Theme
class ThemeAwareTableView: UITableView {
override init(frame: CGRect, style: UITableViewStyle) {
super.init(frame: frame, style: style)
observeTheme(self.dynamicType.themeDidChange)
}
func themeDidChange(theme: Theme) {
separatorColor = theme.colorForKeyPath("tableView.separatorColor")
backgroundColor = theme.colorForKeyPath("tableView.backgroundColor")
}
...
}
License
Theme is released under the MIT license. See LICENSE for details.