Answers:
设置外观(代理)后退按钮颜色的新方法是:
let appearance = UINavigationBarAppearance()
// Apply the configuration option of your choice
appearance.configureWithTransparentBackground()
// Create button appearance, with the custom color
let buttonAppearance = UIBarButtonItemAppearance(style: .plain)
buttonAppearance.normal.titleTextAttributes = [.foregroundColor: UIColor.white]
// Apply button appearance
appearance.buttonAppearance = buttonAppearance
// Apply tint to the back arrow "chevron"
UINavigationBar.appearance().tintColor = UIColor.whiteI
// Apply proxy
UINavigationBar.appearance().standardAppearance = appearance
// Perhaps you'd want to set these as well depending on your design:
UINavigationBar.appearance().compactAppearance = appearance
UINavigationBar.appearance().scrollEdgeAppearance = appearance
我有一个自定义导航控制器安装在我的应用程序,该修改navigationBar
小号titleTextAttributes
,tintColor
和其他人根据不同的场景。
在iOS 13上运行该应用程序时,backBarButtonItem
箭头具有默认的蓝色调颜色。视图调试器显示只有UIBarButtonItem
s UIImageView
具有这种蓝色。
我最终要做的是设置navigationBar.tintColor
两次以更改颜色。
public class MyNavigationController: UINavigationController, UINavigationControllerDelegate {
public var preferredNavigationBarTintColor: UIColor?
override public func viewDidLoad() {
super.viewDidLoad()
delegate = self
}
public func navigationController(_ navigationController: UINavigationController, willShow viewController: UIViewController, animated: Bool) {
// if you want to change color, you have to set it twice
viewController.navigationController?.navigationBar.tintColor = .none
viewController.navigationController?.navigationBar.tintColor = preferredNavigationBarTintColor ?? .white
// following line removes the text from back button
self.navigationItem.backBarButtonItem = UIBarButtonItem(title: "", style: .plain, target: nil, action: nil)
}
寻找解决方案时最奇怪的部分是结果不一致,这让我认为它与视图生命周期和/或外观动画或Xcode缓存有关:)
.none
或者nil
,我只是给它的颜色设置,出现后,它就可以工作