Load your colors into Theme.shared
using ThemeColors
which conforms to Codeable
, so you can load a JSON file from your Bundle (e.g. mytheme.json
)
let myThemeColors = ThemeColors.load(bundle: "mytheme")
or any from any URL
let myThemeColors = ThemeColors.load(url: URL(string: "https://example.com/mytheme.json")!)
and apply the Theme using (if force
is true
it will also reload the current view=
Theme.shared.apply(force: true)
Load your Theme mytheme.json
at the start of the app.
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
Theme.shared.colors = ThemeColors.from(bundle: "mytheme")
Theme.shared.apply(force: true)
return true
}
If your app is using Eureka you can enable support for it with Theme.shared.eureka = true
If you want to customize the colors (for example a user customizable global tint color) before applying the theme you can do so in
Theme.shared.customColor {
// Load custom Colors, e.g.
Theme.shared.tint = ... // Load user tint
}
You can also add your custom apperance setters here
Theme.shared.customAppearances {
// Load custom appearances, e.g.
UIButton.appearance(whenContainedInInstancesOf [MyViewController.self]).backgroundColor = .green
}
Themeable is available through Carthage. To install just write into your Cartfile:
github "divadretlaw/Themeable"
See LICENSE