[英]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.