Reputation: 4079
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?
Upvotes: 1
Views: 7798
Reputation: 1136
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];
}
Upvotes: 5
Reputation: 1044
self.navigationController.navigationBar.tintColor=[UIColor colorWithRed:(45/255.f) green:(45/255.f) blue:(45/255.f) alpha:1.0f];
Upvotes: 1
Reputation: 6445
You need to check the OS version. If it is IOS7, then you can use barTintColor. In IOS6, you can use tintColor
if ([self checkOSVersion] >= 7) {
[[UINavigationBar appearance] setBarTintColor:[UIColor UIColorFromRGB(0x212121)]];
[[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];
} else {
[[UINavigationBar appearance] setTintColor:[UIColor UIColorFromRGB(0x212121)]];
}
define the OS version checking method as
- (int)checkOSVersion {
NSArray *ver = [[[UIDevice currentDevice] systemVersion] componentsSeparatedByString:@"."];
int osVerson = [[ver objectAtIndex:0] intValue];
return osVerson;
}
Upvotes: 2
Reputation: 6079
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)];
}
}
Upvotes: 5
Reputation: 3653
[self.navigationController.navigationBar setTintColor:[UIColor redColor]];
Upvotes: 1