jack moseley
jack moseley

Reputation: 429

Different UINavigationBar background for different views

I am creating my UINavigationBar in code like so:

// init and add root navigation controller to view
_rootNavigationController = [[UINavigationController alloc] init];
[_rootView.contentContainer addSubview:_rootNavigationController.view];
_rootNavigationController.navigationBar.barStyle = UIBarStyleBlackTranslucent;

Then inside a certain UIViewController I want the UINavigationBar to have a clear background, so i use this code which works:

UINavigationBar *navBar = self.navigationController.navigationBar;
navBar.topItem.title = @"";
[navBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
[navBar setShadowImage:[UIImage new]];
[navBar setTranslucent:YES];
[navBar setTintColor:[[AVOThemeManager sharedTheme] contentBackButtonColor]];

Once the user leaves this page by pressing back, I want to return my UINavigationBar back to how it origonally looked, so I am trying this:

- (void)viewDidDisappear:(BOOL)animated {
    UINavigationBar *navBar = self.navigationController.navigationBar;
    [navBar setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];
    [navBar setShadowImage:nil];
    [navBar setBarStyle:UIBarStyleBlackTranslucent];
    [navBar setTranslucent:YES];
}

But this does not seem to work. I also do not want to set the UINavigationBar to be a new instance, and then set the properties, because it has a global button which is added in the root navigation controller, which the child view controllers don't know about.

Is there anything else I can try?

Upvotes: 0

Views: 106

Answers (1)

jack moseley
jack moseley

Reputation: 429

After posting, I immediately found the answer. Basically instead of using viewDidDisappear, I should use viewWillDisappear and it worked.

Upvotes: 2

Related Questions