5

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.

Irfan
  • 4,301
  • 6
  • 29
  • 46
Mayank Purwar
  • 265
  • 1
  • 4
  • 16

5 Answers5

14

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]];
}
Tarek Hallak
  • 18,422
  • 7
  • 59
  • 68
  • The problem with appearance is it is global. This doesn't work for me as it causes tons of bugs all over with incorrect colors on navigation bars after I run this code. I need to set it on the actual instance.... – LightningStryk Jul 30 '14 at 17:00
  • What ray said. Using respondsToSelector for version checking may be better. – user1898829 Nov 10 '14 at 06:51
  • If you need to change only the current navigation bar's appearance you could use: `self.navigationController.navigationBar.tintColor = [UIColor anyColor];` `self.navigationController.navigationBar.barTintColor = [UIColor anyColor];` – Islam Feb 19 '15 at 08:04
7

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]];
Hitesh Vaghela
  • 1,635
  • 1
  • 11
  • 11
2

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]];
 }
Lei
  • 318
  • 1
  • 6
0

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()
alitosuner
  • 984
  • 1
  • 10
  • 15
-1

Try [self.navigationController.navigationBar setTranslucent:NO];

coder1010
  • 412
  • 5
  • 15