Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom navigation bar changes in one viewcontroller

I am working with a custom navigation bar. In my AppDelegate I've done this.

[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"navbar"] forBarMetrics:UIBarMetricsDefault];
[[UINavigationBar appearance] setTitleTextAttributes: @{
                            UITextAttributeTextColor: [UIColor whiteColor],
                      UITextAttributeTextShadowColor: [UIColor whiteColor],
                     UITextAttributeTextShadowOffset: [NSValue valueWithUIOffset:UIOffsetMake(0.0f, 1.0f)],
                                 UITextAttributeFont: [UIFont fontWithName:@"Carrois Gothic" size:18.0f]
 }];

On viewController level I put buttons inside the navigationController. In all viewControllers I have only one button inside the navigationbar.

But in one VC I need to set 2 buttons and I also change the backgroundImage of the navigationbar. So what I copied the same code as above in the ViewDidLoad but now with other image. This is working.

But now I want in all other VC's the first navigationbar. So in my viewDidDisappear I copied again the code with the other image again.

The following is going wrong:

  • The background image is not changing
  • The leftbarbutton is not going away

Can anybody help me with this ?

PS: I am working with a tabbarcontroller. So if I say switching VC's I mean going to another tab in the tabbarcontroller

like image 676
Steaphann Avatar asked Aug 29 '26 22:08

Steaphann


1 Answers

Do not use the appearance proxy in the ViewController. Just set the background directly:

[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"navbar"] forBarMetrics:UIBarMetricsDefault];
[self.navigationController.navigationBar setTitleTextAttributes: @{
                         UITextAttributeTextColor: [UIColor whiteColor],
                  UITextAttributeTextShadowColor: [UIColor whiteColor],
                 UITextAttributeTextShadowOffset: [NSValue valueWithUIOffset:UIOffsetMake(0.0f, 1.0f)],
                             UITextAttributeFont: [UIFont fontWithName:@"Carrois Gothic" size:18.0f]
}];
like image 197
dasdom Avatar answered Sep 01 '26 17:09

dasdom



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!