繁体   English   中英

设置后退按钮颜色

[英]Set back button color

我已将所有条形按钮项目(包括后退按钮)设置为...

UIBarButtonItem.appearance.tintColor = UIColor.red

但是,我想覆盖一页上的后退按钮颜色,但是找不到对后退按钮的引用。 具有正确冠冕堂皇名称的所有引用均为空。

为什么它们都为空? 后退按钮从哪里来?

不使用appearance代理尝试它。 将主窗口的tintColor属性设置为默认颜色。 然后在您的特定视图控制器的viewWillAppear / viewWillDisappear设置/重置特定颜色:

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow? {
        didSet {
            // set your default tint color
            window?.tintColor = .red
        }
    }

}

class SpecificViewController: UIViewController {

    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        navigationController?.navigationBar.tintColor = .magenta
    }

    override func viewWillDisappear(_ animated: Bool) {
        navigationController?.navigationBar.tintColor = nil
        super.viewWillDisappear(animated)
    }

}

结果是:

结果

您应该做的是设置navigationBar.tintColor

UINavigationBar.appearance.tintColor = .red

这会将颜色应用于每个导航栏。 因此,您必须在要更改颜色的视图控制器中再次进行设置和重置。

viewWillAppear

self.navigationContoller?.navigationBar.tintColor = .blue

viewWillDisappear

self.navigationController?.navigationBar.tintColor = .red

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM