Swiftpack.co - Package - DavidSkrundz/Themable

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()
	}
}

Github

link
Stars: 0

Dependencies

Used By

Total: 0