Themeable 0.8.0

Themeable 0.8.0

Tests测试
Lang语言 SwiftSwift
许可证 MIT
Released上次发布2018年1月
SPM支持 SPM

Ed Wellbrook 维护。



Themeable 0.8.0

  • 作者
  • Ed Wellbrook

Themeable

Swift 中的简单、类型安全的 UI 主题化。

欢迎提出 pull request。

特点

  • 类型安全的 API
  • 内存管理透明
  • 自动重用上次使用的主题
  • 线程安全的 UI 更新
  • 无需子类化的 Theme Views 和 Controls
  • 极其灵活(以适合您的任何方式构建和加载主题)

安装

使用 CocoaPods 安装

# In your Podfile add the following, then
# save and run `pod install`:
pod 'Themeable'

示例用法

import UIKit
import Themeable

// Define the theme and its properties to be used throughout your app
struct MyAppTheme: Theme {

    let identifier: String
    let seperatorColor: UIColor
    let lightBackgroundColor: UIColor
    let statusBarStyle: UIStatusBarStyle

    static let light = MyAppTheme(
        identifier: "co.brushedtype.Themeable.light-theme",
        seperatorColor: .lightGray,
        lightBackgroundColor: .white,
        statusBarStyle: .default
    )

    static let dark = MyAppTheme(
        identifier: "co.brushedtype.Themeable.dark-theme",
        seperatorColor: .black,
        lightBackgroundColor: .gray,
        statusBarStyle: .lightContent
    )

    // Expose the available theme variants
    static let variants: [MyAppTheme] = [ .light, .dark ]

    // Expose the shared theme manager
    static let manager = ThemeManager<MyAppTheme>(default: .light)

}

// Conform to the `Themeable` protocol and register for updates
class TableViewController: UITableViewController, Themeable {

    override func viewDidLoad() {
        super.viewDidLoad()

        // register the themeable items once all the view and subviews
        // have been loaded
        MyAppTheme.manager.register(themeable: self)
    }

    // function will be called whenever the theme changes
    func apply(theme: MyAppTheme) {
        self.tableView.separatorColor = theme.seperatorColor
        self.tableView.backgroundColor = theme.lightBackgroundColor
    }

}

许可证

MIT 许可证 (MIT)