在我的整个iOS应用中,我想在导航栏中显示带有文本的自定义后退按钮。
这是我的代码:
let navBarAppearance = UINavigationBar.appearance()
navBarAppearance.backIndicatorImage = #imageLiteral(resourceName: "back")
navBarAppearance.backIndicatorTransitionMaskImage = #imageLiteral(resourceName: "back")
UIBarButtonItem.appearance().setBackButtonTitlePositionAdjustment(UIOffsetMake(0, -60), for: .default)
但是当我运行代码时,它抛出的警告与我最后一行代码的布局有关。如何在没有文本的情况下使用自定义后退按钮,并且在编译期间不会收到任何警告运行时间?
答案 0 :(得分:0)
您可以在AppDelegate中写下此代码,删除整个应用程序的后退按钮文本;
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
//Delete Text of Back Button
let BarButtonItemAppearance = UIBarButtonItem.appearance()
BarButtonItemAppearance.setTitleTextAttributes([NSAttributedStringKey.foregroundColor: UIColor.clear], for: .normal)
return true
}
如需更多答案,请查看以下帖子;