LS_
LS_

Reputation: 7139

How to hide Navigation Bar back button title from AppDelegate

Whenever my app receives a push notification with custom payload I'd like to push the app to a UIViewController, I was able to do it but I cannot remove the title from the Back button of the UINavigationBar from the AppDelegate.

What I tried was:

    [self.window.rootViewController.navigationController setNavigationBarHidden:NO];
    [self.window.rootViewController.navigationController.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
    [self.window.rootViewController.navigationController.navigationBar setShadowImage:[UIImage new]];
    [self.window.rootViewController.navigationController.navigationBar setTranslucent:YES];
    [self.window.rootViewController.navigationController.navigationBar setTintColor:[UIColor mainBlue]];
    self.window.rootViewController.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:self.window.rootViewController.navigationItem.backBarButtonItem.style target:nil action:nil];

The last line is where I set the title of the back button to nil but it doesn not work, when the UIViewController becomes visible I can still se the title. The code works if I use it on the UIViewController before that one but not on the AppDelegate. Does anyone have a solution? What am I doing wrong?

Upvotes: 1

Views: 894

Answers (1)

Hemang
Hemang

Reputation: 27072

[[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(0, -60) forBarMetrics:UIBarMetricsDefault];

This will hide back button title from all navigation items. You should change the offset value based on your title length.

Upvotes: 2

Related Questions