TestsTested | ✗ |
LangLanguage | SwiftSwift |
License | MIT |
ReleasedLast Release | Jan 2018 |
SPMSupports SPM | ✓ |
Maintained by Ed Wellbrook.
Easy, type-safe UI theming in Swift.
Pull requests are always very welcome.
Installing with CocoaPods:
# In your Podfile add the following, then
# save and run `pod install`:
pod 'Themeable'
import UIKit
import Themeable
// Define the theme and its properties to be used throughout your app
struct MyAppTheme: Theme {
let identifier: String
let seperatorColor: UIColor
let lightBackgroundColor: UIColor
let statusBarStyle: UIStatusBarStyle
static let light = MyAppTheme(
identifier: "co.brushedtype.Themeable.light-theme",
seperatorColor: .lightGray,
lightBackgroundColor: .white,
statusBarStyle: .default
)
static let dark = MyAppTheme(
identifier: "co.brushedtype.Themeable.dark-theme",
seperatorColor: .black,
lightBackgroundColor: .gray,
statusBarStyle: .lightContent
)
// Expose the available theme variants
static let variants: [MyAppTheme] = [ .light, .dark ]
// Expose the shared theme manager
static let manager = ThemeManager<MyAppTheme>(default: .light)
}
// Conform to the `Themeable` protocol and register for updates
class TableViewController: UITableViewController, Themeable {
override func viewDidLoad() {
super.viewDidLoad()
// register the themeable items once all the view and subviews
// have been loaded
MyAppTheme.manager.register(themeable: self)
}
// function will be called whenever the theme changes
func apply(theme: MyAppTheme) {
self.tableView.separatorColor = theme.seperatorColor
self.tableView.backgroundColor = theme.lightBackgroundColor
}
}
The MIT License (MIT)