尝试通过协议设置几个不同的颜色主题,并且可以更新按钮,标签等,但不能更改选项卡栏项目的色泽。如何实现并使其在应用程序中更新。
ThemeProtocol.swift
protocol ThemeProtocol {
var background: UIColor { get }
var accent: UIColor { get }
var tint: UIColor { get }
}
RedTheme.swift
class RedTheme: ThemeProtocol {
var background: UIColor = UIColor.systemBackground
var accent: UIColor = UIColor.systemRed
var tint: UIColor = UIColor.systemRed
}
实施
override func viewWillAppear(_ animated: Bool) {
super.viewDidAppear(animated)
applyTheme()
}
private func applyTheme() {
settingsButton.tintColor = ThemeManager.current.tint
}
}