How do I change the Navigation Bar color in iOS 7?
Basically I want to achieve something like the Twitter Nav Bar (updated Twitter for iOS7
that is). I embedded-in a nav bar atop a view controller
. All I want is to change the nav bar color to light blue along with the utility bar at the top. I can't seem to find an option in my storyboard
.
The behavior of tintColor
for bars has changed in iOS 7.0. It no longer affects the bar's background.
From the documentation:
barTintColor Class Reference
The tint color to apply to the navigation bar background.
@property(nonatomic, retain) UIColor *barTintColor
Discussion
This color is made translucent by default unless you set the translucent property to NO
.
Availability
Available in iOS 7.0 and later.
Declared In
UINavigationBar.h
NSArray *ver = [[UIDevice currentDevice].systemVersion componentsSeparatedByString:@"."]; if ([[ver objectAtIndex:0] intValue] >= 7) { // iOS 7.0 or later self.navigationController.navigationBar.barTintColor = [UIColor redColor]; self.navigationController.navigationBar.translucent = NO; }else { // iOS 6.1 or earlier self.navigationController.navigationBar.tintColor = [UIColor redColor]; }
We can also use this to check iOS Version as mention in iOS 7 UI Transition Guide
if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_6_1) { // iOS 6.1 or earlier self.navigationController.navigationBar.tintColor = [UIColor redColor]; } else { // iOS 7.0 or later self.navigationController.navigationBar.barTintColor = [UIColor redColor]; self.navigationController.navigationBar.translucent = NO; }
EDIT Using xib
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With