0

In my entire iOS app, I want to show custom back button in navigation bar with out text.
Here's my code:

let navBarAppearance = UINavigationBar.appearance()
navBarAppearance.backIndicatorImage = #imageLiteral(resourceName: "back")
navBarAppearance.backIndicatorTransitionMaskImage = #imageLiteral(resourceName: "back")
UIBarButtonItem.appearance().setBackButtonTitlePositionAdjustment(UIOffsetMake(0, -60), for: .default)

But when I'm running the code, its throwing warnings related to layout for my last line of code. How can I have custom back button without text and without getting any warnings during compile & run time?

Satyam
  • 15,493
  • 31
  • 131
  • 244

1 Answers1

0

You can delete text of back button for whole app with writing this code inside 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
}

For more answers, please check below post;

Remove text from Back button keeping the icon

Emre Önder
  • 2,408
  • 2
  • 23
  • 73
  • 1
    Bad approach. That will clear the text color of all bar buttons. Also since the text is still there it will take touches. – HAK May 03 '18 at 07:32
  • if you copy and paste the answer please add the ref : https://stackoverflow.com/questions/23853617/uinavigationbar-hide-back-button-text of copy – Anbu.Karthik May 03 '18 at 07:37
  • @Anbu.karthik I added different reference which yurs doesn't have my answer. – Emre Önder May 03 '18 at 07:43
  • @HAK Sorry I couldn't find better approach for this question. What would you suggest? Can you please write ur answer? – Emre Önder May 03 '18 at 07:44