我想更改整个应用程序中所有导航 Controller 中的所有后退箭头。我想避免在每个文件中手动更改图像,因为那会很耗时。我将在我的 AppDelegate 文件中的 didFinishLaunchingWithOptions
方法中发布我目前拥有的代码。
let backButton = UIImage(named: "backbutton-thin")?.resizableImage(withCapInsets: UIEdgeInsetsMake(0, 0, 16, 16))
let backButtonImage = backButton?.stretchableImage(withLeftCapWidth: 5, topCapHeight: 0)
barButtonAppearance.setBackButtonBackgroundImage(backButtonImage, for: .normal, barMetrics: .default)
let item = UIBarButtonItem.appearance(whenContainedInInstancesOf: [UINavigationController.self])
item.setBackButtonBackgroundVerticalPositionAdjustment(0, for: .default)
item.setBackButtonBackgroundImage(backButtonImage, for: .normal, barMetrics: .default)
代码在我所有的导航栏中产生了这个结果......
如您所见,细箭头与“返回”文本重叠,原始箭头仍然存在。我究竟做错了什么?如何删除原始箭头并用我的细自定义箭头替换它?不过我还是想保留文字。任何帮助将不胜感激。
最佳答案
您需要修改 UINavigationBar
类的 backIndicatorImage
和 backIndicatorTransitionMaskImage
以将现有的后退指示器图像替换为您的自定义图像。
UINavigationBar.appearance().backIndicatorImage = UIImage(named: "backbutton-thin")
UINavigationBar.appearance().backIndicatorTransitionMaskImage = UIImage(named: "backbutton-thin")
关于ios - 如何在应用程序委托(delegate)文件中的整个应用程序中设置自定义导航 Controller 后退箭头图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49439680/