TSCThemer
示例
要运行示例项目,请克隆仓库,然后从 Example 目录首先运行 pod install
。
需求
安装
TSCThemer 通过 CocoaPods 提供。要安装它,只需将以下行添加到您的 Podfile 中。
pod 'TSCThemer'
用法
TSCThemer 只有两个基本部分。一个简单的 Themer
类,其中只有一个成员变量 index
,以及一个 NSObject
的扩展。
当更改索引时,会触发一个通知,通过扩展注册的块将执行这些通知。
要添加一个块,请使用 setTheme()
/// Sets a theme on the given object
///
/// - Parameters:
/// - themer: The Themer to use
/// - index: Corresponds to Themer.index. Indexes need not be sequential.
/// - key: For example "TextColor", "Font", "BackgroundColor", "Layout"
/// - block: A block that will be executed when the theme updates. Called immediately if indexes match.
public func setTheme(themer: Themer = Themer.shared, index: Int, key: String, block: ThemeBlock?)
为常见的UIKit方法提供了方便的方法,例如:backgroundColor
,textColor
,text
,attributedText
等。
self.view.themeBackgroundColor([.red, .blue])
self.button.themeTintColor([.red, .green])
作者
timothycosta, [email protected]
许可
TSCThemer遵循MIT许可。有关更多信息,请参阅LICENSE文件。