在我的应用程序中,我想删除UINavigationBar
后退按钮标题。我已经完成了以下代码
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// do other staffs
initNavigationBar()
return true
}
private func initNavigationBar() {
let appearance = UINavigationBar.appearance()
appearance.barTintColor = GLOBAL_TINT_COLOR // a globally declared colour
appearance.tintColor = .white
appearance.barStyle = .black
if #available(iOS 13.0, *) {
let backButtonAppearance = UIBarButtonItemAppearance()
backButtonAppearance.normal.titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.clear]
appearance.standardAppearance.backButtonAppearance = backButtonAppearance
appearance.compactAppearance?.backButtonAppearance = backButtonAppearance
appearance.scrollEdgeAppearance?.backButtonAppearance = backButtonAppearance
} else {
// Hide navigation bar back button items
UIBarButtonItem.appearance(whenContainedInInstancesOf: [UINavigationBar.self]).setTitleTextAttributes([NSAttributedString.Key.foregroundColor: UIColor.clear], for: .normal)
UIBarButtonItem.appearance(whenContainedInInstancesOf: [UINavigationBar.self]).setTitleTextAttributes([NSAttributedString.Key.foregroundColor: UIColor.clear], for: .highlighted)
}
}
但是,此代码始终适用于iOS 10-12
,但不适用于iOS 13
。我错过了什么吗?
在其他情况下,我找到了很多关于该主题的答案,但没有找到解决方案iOS 13
我从不想使用 to set back button title as an empty string
,而不是使用外观来修复它。
谢谢