Change navigation bar tint color iOS 7.

24,323

Solution 1

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]];

Solution 2

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]];
}

Solution 3

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]];
 }
Share:
24,323
Mayank Purwar
Author by

Mayank Purwar

Currently working on Xcode/Objective C. Have basic knowledge of HTML,PHP and SQL

Updated on August 28, 2020

Comments

  • Mayank Purwar
    Mayank Purwar over 3 years

    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.