Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change NavigationBar color (background color)

I keep reading to change the default color on a navigationbar i just need to update the first method in the appdelegate to this

self.window.rootViewController.navigationController.navigationBar.tintColor = [UIColor whiteColor];

but it doesn't seem to work, so I tried setting it in the viewDidLoad method of the firstview also:

self.parentViewController.navigationController.navigationBar.tintColor = [UIColor whiteColor];

This didn't work either. How can I change this?

like image 944
user869305 Avatar asked Jun 02 '12 18:06

user869305


People also ask

Can you change navigation bar color on android?

You don't need to have root access to change the navigation bar color. You just need to download a free customization app known as the Navbar app which is available on the Google Play Store.


3 Answers

Don't use self.parentViewController, but self:

self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
like image 134
DrummerB Avatar answered Nov 03 '22 17:11

DrummerB


When iphone 5 come we have to set both device type. So use this

if([self.navigationController.navigationBar respondsToSelector:@selector(setBackgroundImage:forBarMetrics:)] ) {
    //iOS 5 new UINavigationBar custom background
    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"navbg_ForiPhone5_Imagename.png"] forBarMetrics: UIBarMetricsDefault];
} else {
    [self.navigationController.navigationBar insertSubview:[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"navbg_ForOtherIphone_Imagename.png"]] atIndex:0];
}
like image 33
Isuru Jayathissa Avatar answered Nov 03 '22 15:11

Isuru Jayathissa


In IOS7 you can try this:

[[UINavigationBar appearance] setBarTintColor:[UIColor redColor]];

You can follow these steps:

I created a new UINavigationController for example UIDemoNavController resulting in:

- (void)viewDidLoad{
    [[UINavigationBar appearance] setBarTintColor:[UIColor redColor]];  
    [super viewDidLoad];
}

This is the full demo class:

#import "UIDemoNavController.h"

@interface UIDemoNavController()

@end

@implementation UIDemoNavController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {}
    return self;
}

- (void)viewDidLoad{
    [[UINavigationBar appearance] setBarTintColor:[UIColor redColor]];
    [super viewDidLoad];
}

- (void)didReceiveMemoryWarning{
    [super didReceiveMemoryWarning];
}

@end
like image 1
Dalorzo Avatar answered Nov 03 '22 17:11

Dalorzo