在iOS13中,苹果引入了新的UINavigationBarAppearance代理对象来设置导航栏的外观。我几乎可以设置我需要的所有东西,除了一个小东西。后退按钮的箭头总是以蓝色呈现,我不知道如何将其设置为我想要的颜色。我使用的是旧的[[UINavigationBar appearance] setTintColor:]方法,但我认为必须有某种方法来使用UINavigationBarAppearance对象API来完成这项工作。有人知道是怎么回事吗?
发布于 2019-10-14 21:23:43
设置外观(代理)的后退按钮颜色的新方法是:
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.white
// 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发布于 2019-10-02 18:35:29
我在我的应用程序中有一个自定义的导航控制器设置,它根据不同的场景修改navigationBar的titleTextAttributes,tintColor和其他。
在iOS 13上运行应用程序时,backBarButtonItem箭头具有默认的蓝色。视图调试器显示,只有UIBarButtonItem的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缓存有关:)
https://stackoverflow.com/questions/58169259
复制相似问题