Skip to content

DavidSkrundz/Themable

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Themable

Create and apply Themes.

  1. Use ThemeController as the root VC

    • ThemeController(viewController: UIViewController)
    • Create a ThemeSegue with the identifier "ThemeSegue"
  2. Create themes

let mainTheme = Theme(...)
let secondTheme = Theme(...)
  1. Create and use a ThemeContext
let themeContext = ThemeContext(theme: mainTheme)
themeContext.controllers.append(themeController)
// Set every UIColor to the `themeContext.*` equivalent
  1. Switch themes
self.themeContext.animateTheme(secondTheme)

Subclassing Theme and ThemeContext to add more colors

class MyContext: ThemeContext {
	public var customColor: UIColor {
		if #available(iOS 13.0, tvOS 13.0, *) {
			return Color.make { traitCollection -> UIColor in
				return self.currentTheme.customColor.resolvedColor(with: traitCollection)
			}
		} else {
			return self.currentTheme.customColor
		}
	}
}
class MyTheme: Theme {
	public var customColor: UIColor
	
	public init(customColor: UIColor) {
		self.customColor = customColor
		super.init()
	}
}

About

Create and apply Themes

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages