ThemeManager 是一个非常轻量级、强大、方便且最简单的管理应用程序主题的方式,并且还支持动态更改文本(例如语言)或其他配置。
ThemeManager 支持 CocoaPods 和 Carthage。ThemeManager 使用 Swift 编写。
您可以拉取 ThemeManager Github 仓库,并包含 ThemeManager.xcodeproj 来构建动态或静态库。
CocoaPods 是 Cocoa 项目的依赖管理器。有关用法和安装说明,请访问他们的网站。要使用 CocoaPods 将 ThemeManager 集成到您的 Xcode 项目中,请在您的 Podfile
中指定它。
pod 'WYZThemeManager'
Carthage 是一个去中心化的依赖管理器,它可以构建您的依赖项并为您提供二进制框架。要使用 Carthage 将 ThemeManager 集成到您的 Xcode 项目中,请在您的 Cartfile
中指定它。
github "azone/ThemeManager" "master"
Swift Package Manager 是一种用于自动化 Swift 代码分发的工具,并已集成到 Swift 编译器中。 它仍在早期开发阶段,但 ThemeManager 确实支持在支持的平台上使用它。
设置好您的 Swift 包后,将 ThemeManager 添加为依赖项就像将其添加到 Package.swift
的 dependencies 值一样简单。
dependencies: [
.package(url: "https://github.com/azone/ThemeManager.git", from: "0.3.0")
]
示例
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"
}
示例
let themeManager = ThemeManager(MyTheme())
示例
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
}
themeManager.apply(otherTheme)
ThemeManager 在 MIT 许可证下发布。有关详细信息,请参阅 LICENSE。