Q:

how to set navigation bar color on IOS 6/7

i am setting my UINAvigatoinBar color like so with hex color:
self.navigationController.navigationBar.barTintColor = UIColorFromRGB(0x212121);

it works well on IOS7 but in lower versions it crash with the following :
[UINavigationBar setBarTintColor:]: unrecognized selector sent to instance

how can i do it right? 

A:

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

A:

the best solution is detect which version of os is:
-(void)viewWillAppear:(BOOL)animated {

   NSString *ver = [[UIDevice currentDevice] systemVersion];
   int ver_int = [ver intValue];

   if (ver_int < 7) {
       [self.navigationController.navigationBar setTintColor:[UIColor UIColorFromRGB(0x212121)]];
    }

   else {
    self.navigationController.navigationBar.barTintColor = [UIColor UIColorFromRGB(0x212121)];
   }

 }

A:

I assume the best way is to be using the respondToSelector method instead of checking the iOS version:
if ([self.navigationController.navigationBar respondsToSelector:@selector(setBarTintColor:)]) {
    [self.navigationController.navigationBar setBarTintColor:NAVBAR_BACKGROUNDCOLOR];
}
else {
    [self.navigationController.navigationBar setTintColor:NAVBAR_BACKGROUNDCOLOR];
}

