Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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...

like image 739
MikeS Avatar asked Sep 18 '13 22:09

MikeS


2 Answers

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.

like image 163
Roshan Avatar answered Sep 19 '22 01:09

Roshan


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 
like image 29
dan Avatar answered Sep 22 '22 01:09

dan