How to Change Navigation Bar Color in iOS 7 or 6

How to set status bar color same as to Navigation bar color in iOs 7 using Xcode 4.2

In iOS6 you can't change the image or the color of the status bar apart from this 2 styles:

[[UIApplication sharedApplication]setStatusBarStyle:UIStatusBarStyleBlackOpaque];

[[UIApplication sharedApplication]setStatusBarStyle:UIStatusBarStyleBlackTranslucent];

Navigation bar in iOS 6 look like bar in iOS 7

Instead of putting code into every view controller that you need to customize, I would recommend doing this for the entire application by putting something like this in your application:didFinishLaunchingWithOptions: method in the App Delegate

// Nav bar
[[UINavigationBar appearance] setBackgroundImage:[[UIImage imageNamed:@"navBar.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(10, 5, 10, 5)] forBarMetrics:UIBarMetricsDefault];

// Back buttons
[[UIBarButtonItem appearance] setBackButtonBackgroundImage:[UIImage imageNamed:@"backNavButton.png"] forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];

// Toolbar
[[UIToolbar appearance] setBackgroundImage:[[UIImage imageNamed:@"toolbar.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(10, 5, 10, 5)] forToolbarPosition:UIToolbarPositionAny barMetrics:UIBarMetricsDefault];

Change navigation bar tint color iOS 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]];

Unable to change navigation bar color

There are two ways to do this. You can either modify the appearance proxy that you have set up in the AppDelegate for the whole app, or you can modify the individual navigationbar for the particular screen.

When you dismiss the view - you need to reset the barTintColor in the viewWillDisappear.

override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)

// Set to new colour for whole app
UINavigationBar.appearance().barTintColor = UIColor.blueColor()

// Or, Set to new colour for just this navigation bar
self.navigationController?.navigationBar.barTintColor = UIColor.blueColor()
}

override func viewWillDisappear(animated: Bool) {
super.viewWillDisappear(animated)

//Revert to old colour, whole app
UINavigationBar.appearance().barTintColor = UIColor.redColor()

//Revert to old colour, just this navigation bar
self.navigationController?.navigationBar.barTintColor = UIColor.redColor()
}


Related Topics



Leave a reply



Submit