Reputation: 265
I know how to change navigation bat tint colour in iOS 6:
[UINavigationBar appearance].tintColor = [UIColor colorWithRed:129/255.0 green:200/255.0 blue:244/255.0 alpha:1.0];
I'm adding this code in APPDelegate page. Now I want to do this in iOS 7 but above code is not working. I searched on net. I got a solution. By adding below function to every page I can change navigation color.
self.navigationController.navigationBar.barTintColor = [UIColor colorWithRed:129/255.0 green:200/255.0 blue:244/255.0 alpha:1.0];
But I need a function which can add to APPDelegate function. Please help me to overcome this issue.
Upvotes: 5
Views: 24343
Reputation: 1034
In Swift, for me, I wanted to change tint color for the Cancel and Send buttons, when the e-mail pops up. And it worked great.
(UIBarButtonItem.appearanceWhenContainedInInstancesOfClasses([UINavigationBar.self])).tintColor = UIColor.whiteColor()
Upvotes: 0
Reputation: 412
Try [self.navigationController.navigationBar setTranslucent:NO];
Upvotes: -1
Reputation: 318
Using respondsToSelector for version checking may be better.
if ([self.navigationBar respondsToSelector:@selector(setBarTintColor:)]) {
[self.navigationBar setBarTintColor: [UIColor colorWithRed:129/255.0 green:200/255.0 blue:244/255.0 alpha:1.0]];
} else {
[self.navigationBar setTintColor: [UIColor colorWithRed:129/255.0 green:200/255.0 blue:244/255.0 alpha:1.0]];
}
Upvotes: 2
Reputation: 1635
you can add bellow code in appdelegate.m
if your app is navigation based
// for background color
[nav.navigationBar setBarTintColor:[UIColor blueColor]];
// for change navigation title and button color
[[UINavigationBar appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor], NSForegroundColorAttributeName, [UIFont fontWithName:@"FontNAme" size:20], NSFontAttributeName, nil]];
[[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];
Upvotes: 7
Reputation: 18470
Why not to use setBarTintColor
for appearance proxy, you can do this:
if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_6_1)
{
[[UINavigationBar appearance] setTintColor: [UIColor colorWithRed:129/255.0 green:200/255.0 blue:244/255.0 alpha:1.0]];
}
else
{
[[UINavigationBar appearance] setBarTintColor: [UIColor colorWithRed:129/255.0 green:200/255.0 blue:244/255.0 alpha:1.0]];
}
Upvotes: 14