Skip to content
This repository has been archived by the owner on Feb 5, 2021. It is now read-only.
/ Themeable Public archive

🎨 Simple way for Theme support in iOS apps

License

Notifications You must be signed in to change notification settings

divadretlaw/Themeable

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

themeable

Themeable Build Status Carthage Swift License

Usage

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)

Example

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
}

Advanced

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
}

Installation

Themeable is available through Carthage. To install just write into your Cartfile:

github "divadretlaw/Themeable"

License

See LICENSE