ThemeManager
ThemeManager 是管理您应用主题最轻量级、功能强大、便捷易懂的方式,同时支持动态修改文本(例如语言)或其他配置。
安装 ThemeManager
ThemeManager 支持 CocoaPods 和 Carthage。ThemeManager 使用 Swift 编写。
GitHub 仓库
您可以拉取 ThemeManager GitHub 仓库 并包含 ThemeManager.xcodeproj 来构建动态或静态库。
CocoaPods
CocoaPods 是 Cocoa 项目的依赖管理器。有关使用和安装说明,请访问他们的网站。要在 Xcode 项目中使用 CocoaPods 集成 ThemeManager,请在您的 Podfile
中指定它。
pod 'WYZThemeManager'
Carthage
Carthage 是一个去中心化的依赖项管理器,它构建你的依赖项并提供二进制框架。要使用 Carthage 将 ThemeManager 集成到你的 Xcode 项目中,请在你的 Cartfile
中指定它。
github "azone/ThemeManager" "master"
Swift 包管理器
Swift 包管理器 是一个用于自动分发 Swift 代码的工具,它集成到 Swift 编译器中。处于早期开发阶段,但 ThemeManager 支持在支持的平台上使用它。
一旦你设置了你的 Swift 包,添加 ThemeManager 作为依赖项就像将它添加到你的 Package.swift
的 dependencies
值一样简单。
dependencies: [
.package(url: "https://github.com/azone/ThemeManager.git", from: "0.3.0")
]
用法
Theme
协议。
1. 实现自己的主题语言或其它配置(可能是类、结构体或你想要任何事情),它必须遵守 示例
import ThemeManager
struct MyTheme: Theme {
var backgroundColor = UIColor.gray
var mainColor = UIColor.orange
var titleFont = UIFont.preferredFont(forTextStyle: .headline)
var subtitleFont = UIFont.preferredFont(forTextStyle: .subheadline)
var textColor = UIColor.red
var buttonTitleColor = UIColor.orange
var buttonTitleHighlightcolor = UIColor.red
var title = "Default Theme"
}
ThemeManager
实例变量。
2. 在全局范围内声明带有你的默认主题的 示例
let themeManager = ThemeManager(MyTheme())
setUp
方法中。
3. 将任何主题、语言或配置相关的设置放入 示例
themeManager.setup(view) { (view, theme) in
view.backgroundColor = theme.backgroundColor
}
themeManager.setup(navigationItem) { (item, theme) in
item.title = theme.title
}
themeManager.setup(navigationController?.navigationBar) { (bar, theme) in
bar.tintColor = theme.mainColor
bar.barTintColor = theme.backgroundColor
}
4. 使用您的主题实例更改另一个主题、语言或配置
themeManager.apply(otherTheme)
授权
ThemeManager在MIT许可证下发布。有关详情,请参阅LICENSE。