[英]Remove title or text for back button in iOS app for entire app
在我的整個iOS應用中,我想在導航欄中顯示不帶文字的自定義后退按鈕。
這是我的代碼:
let navBarAppearance = UINavigationBar.appearance()
navBarAppearance.backIndicatorImage = #imageLiteral(resourceName: "back")
navBarAppearance.backIndicatorTransitionMaskImage = #imageLiteral(resourceName: "back")
UIBarButtonItem.appearance().setBackButtonTitlePositionAdjustment(UIOffsetMake(0, -60), for: .default)
但是,當我運行代碼時,它的拋出警告與我最后一行代碼的布局有關。 在編譯和運行時如何在沒有文本且沒有任何警告的情況下擁有自定義的后退按鈕?
您可以通過在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
}
有關更多答案,請檢查以下帖子;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.