Skip to content
/ iTheme Public template

Use and build material themes easily with iTheme for iOS

Notifications You must be signed in to change notification settings

TristanBilot/iTheme

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Ask Me Anything !

iTheme

iTheme is a simple Theme manager. You can easily:

  • switch between different themes
  • add/modify themes
  • automatically store the last selected theme

Peek a color

self.view.backgroundColor = ITheme.backgroundColor
self.description.textColor = ITheme.subtitle

Set gradient background

ITheme.setGradientBackground(self.view)

Add a new theme

To add a new theme, just add the name of your brand new theme in the (String => func()) dictionnary:
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.