iTheme is a simple Theme manager. You can easily:
- switch between different themes
- add/modify themes
- automatically store the last selected theme
self.view.backgroundColor = ITheme.backgroundColor
self.description.textColor = ITheme.subtitle
ITheme.setGradientBackground(self.view)
fileprivate static let themes =
[
"light": light,
"dark": dark,
"material": material
"myCoolTheme": myCoolTheme
...
]
Then, you must implement the function associated to your theme like this:
static let myCoolTheme: () -> () = {
loadPalette(lightPal)
saveTheme("myCoolTheme")
}
The loadPalette() method will load your theme colors defined in a specific array:
fileprivate static let lightPal =
[
UIColor(rgb: 0x3F51B5), UIColor(rgb: 0xFFFFFF), UIColor(rgb: 0xebebeb),
UIColor(rgb: 0xFFFFFF), UIColor(rgb: 0x212121), UIColor(rgb: 0x212121),
UIColor(rgb: 0x212121)
]
fileprivate static let darkPal = [...]
fileprivate static let materialPal = [...]
...
Finally, saveTheme() stores the name of your theme in the UserDefaults of the iOS device. Thus, the user can fetch the last used theme even if the app is closed and restarted.