iOS 7 : Disable UINavigationBar Translucency For Entire App

Is there a way to disable UINavigationBar Translucency for an entire application?

I'm aware that using [self.navigationController.navigationBar setTranslucent:NO] can fix this issue for a single controller, but I have a lot of UINavigationBars in my application and this is a pretty tedious solution.

I've tried [[UINavigationBar appearance] setTranslucent:NO], but that functionality is surprisingly not supported. Doing that results in Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** Illegal property type, c for appearance setter, _installAppearanceSwizzlesForSetter:'

If I HAVE to, I can go through my entire app setting UINavigationBars to disable translucency one by one, but there must be some more elegant solution to this issue...


Solution 1:

if you set the translucence of the first navigation bar in the stack to false [self.navigationController.navigationBar setTranslucent:NO], it will reflect in all the following NavigationViewController that are pushed to that stack.

Solution 2:

Here is a Swift solution if you want to apply this Styling to the whole app.

in the AppDelegate class add this to the didFinishLaunchingWithOptions:

For Swift 2:

UINavigationBar.appearance().translucent = false

For Swift 3+:

UINavigationBar.appearance().isTranslucent = false

Solution 3:

It seems very simple with this code in appDelegate didFinishLaunchingWithOptions (works fine with iOS 8 and above versions)

[[UINavigationBar appearance] setTranslucent:NO];

Solution 4:

I think you are right about no appearance proxy being available for this property. Are you using UINavigationControllers or UINavigationBar objects? If you are using UINavigationBars you could subclass it and create a non-translucent nav bar.

Header file:

#import <UIKit/UIKit.h>

@interface ABCNonTranslucentNavBar : UINavigationBar

@end

Implementation file:

#import "ABCNonTranslucentNavBar.h"

@implementation ABCNonTranslucentNavBar

- (void)drawRect:(CGRect)rect
{
  [self setTranslucent:NO];
}

Then just replace the UINavigationBars with your subclass. You could also do something similar with a subclassed UINavigationController.

Solution 5:

Adding this in case anyones still battling this.

You can fool it though by specifying a non exist image, which will make the nav bar INCLUDING it's tool bar go opaque

[[UIToolbar appearance] setBackgroundColor:[UIColor colorWithRed:219.0/255.0 green:67.0/255.0 blue:67.0/255.0 alpha:1.0]];

[[UIToolbar appearance] setBackgroundImage:[[UIImage alloc] init] forToolbarPosition:UIBarPositionAny barMetrics:UIBarMetricsDefault];