0

Suppose, we have two view controllers - Controller A and Controller B.

Tapping on a particular item on Controller A pushes the Controller B. I set the color of the navigation bar buttons in the didFinishLaunchingWithOptions method in my AppDelegate.m using this -

[[UINavigationBar appearance] setTintColor:[UIColor blueColor]];

Works well on every navigation controller I have in my app. What I want is that I have a different color for the buttons on the navigation bar in Controller A and a different color for those in Controller B.

Is this possible?

What I have tried so far...

  1. Put this code in the method in Controller A that pushes Controller B -

    [[UIBarButtonItem appearance] setTintColor:[UIColor whiteColor]];
    

    No go.

  2. This went in the viewWillAppear method of Controller B -

    [[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];
    

    Nothing

    self.navigationItem.backBarButtonItem.tintColor = [UIColor whiteColor];
    

    Still no change.

    [[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];
    

    *about to slam my machine against the wall

(Writing from my new computer) What code should I be using to accomplish this and where should I be putting it?

Thanks in advance.

Sujay
  • 2,510
  • 2
  • 27
  • 47
genaks
  • 757
  • 2
  • 10
  • 24
  • 1
    Please see following may be it help you in your problem [reference][1] [1]: http://stackoverflow.com/a/19029973/3977940 – Pravin Tate Jun 23 '15 at 07:53
  • It did.. All I did was put this line of code [self.navigationController.navigationBar setTintColor:[UIColor whiteColor]]; in the viewDidLoad method of Controller B – genaks Jun 23 '15 at 08:01

2 Answers2

0

The line of code should be -

[self.navigationController.navigationBar setTintColor:[UIColor whiteColor]];

and it goes in the viewDidAppear method of Controller B.

Remember to put it back to your default color in the viewDidDisappear method of Controller B so when you navigate from Controller B, you do not get unexpected results.

(maybe the new computer brought me some luck)

genaks
  • 757
  • 2
  • 10
  • 24
  • it works if you put it it in the `viewWillAppear' method as well. – genaks Jun 23 '15 at 08:12
  • Hmmm... putting the color back to default in viewDidDisappear did not work completely, the right side buttons of the navigation bar are still white – genaks Jun 23 '15 at 10:18
0

Try to do :

[self setNeedsStatusBarAppearanceUpdate];

after update the tintColor of your navbar

AnthonyR
  • 3,485
  • 1
  • 18
  • 41
  • umm.. for changing the color of back button? – genaks Jun 23 '15 at 09:21
  • yes sorry, I use this method to update mine when I make changes. If this don't work, try : self.navigationItem.leftBarButtonItem.tintColor = [UIColor whiteColor]; For example – AnthonyR Jun 23 '15 at 09:39
  • It worked without adding this line of code.. just saying – genaks Jun 23 '15 at 10:06
  • On a sidenote, I used this to change the style of my status bar for a particular and then changing it back to default so thanks :) – genaks Jun 23 '15 at 10:07