在应用中设置色彩,但无法更改标签栏的色彩

时间:2019-06-24 09:24:08

标签: ios swift themes uitabbar uicolor

尝试通过协议设置几个不同的颜色主题,并且可以更新按钮,标签等,但不能更改选项卡栏项目的色泽。如何实现并使其在应用程序中更新。

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
    }
}

0 个答案:

没有答案