Skip to content

Latest commit

 

History

History
73 lines (47 loc) · 1.69 KB

README.md

File metadata and controls

73 lines (47 loc) · 1.69 KB

Theme

Pod Version Pod License Pod Platform

Support one or more configurable appearance themes.

Privacy Manifest

  • This package uses UserDefaults to record the currently selected theme.

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.