0

I'm setting the bar tint color to be different on button click but you have to switch views for the following method to take effect. I have no clue why it is not.

[[UINavigationBar appearance] setBarTintColor:[UIColor darkGrayColor]];

Thanks :D

Colton Anglin
  • 431
  • 3
  • 9
  • 19

2 Answers2

1

The reason for the error:

[[UINavigationBar appearance] setBarTintColor:[UIColor randomColor]]; doesn't work because the UIViewController has been initialized!!!

The solution :

(1) The UIAppearance user to set global effect in AppDelegate didFinishLaunch Function.

 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    // Override point for customization after application launch.

    [[UINavigationBar appearance] setBarTintColor: [UIColor redColor]];
    return YES;
}

(2) About initialized UIViewController ,you should user self.navigationController.navigationBar to set color can have an effect on the app life cycle as well.

[self.navigationController.navigationBar setBarTintColor:[UIColor randomColor]];
Qun Li
  • 1,256
  • 13
  • 13
0
UINavigationBar *navBar=self.navigationController.navigationBar;
[navBar setBarTintColor:[UIColor darkGrayColor]];

Try this

this is how i tested it.

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    UINavigationBar *navBar=self.navigationController.navigationBar;
    [navBar setBarTintColor:[UIColor darkGrayColor]];
}

Since i dont have any button on screen i just changed one of my table delegate function.

m-farhan
  • 1,436
  • 13
  • 14