user2760103
user2760103

Reputation:

How can I make my navigation bar uniformly semi-transparent?

I'm writing an app on iOS 7, and I can't seem to get a handle on the transparency of the navigationBar and the toolbar, how can I set the navigation bar to black at 50% opacity?

I've read the transition to ios7 guide and I've watched the wwdc13 lecture 214, but my status bar still has a different transparency than the rest of the attached nav bar.

Here is my code:

// APP-WIDE THEMING
[[UINavigationBar appearance] setBarStyle:UIBarStyleBlackOpaque];
[[UINavigationBar appearance] setBackgroundColor:[UIColor blueColor]];  
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];

Here is the screenshot of my problem: http://grab.by/qiyU

Upvotes: 0

Views: 5297

Answers (4)

Echo Liao
Echo Liao

Reputation: 91

Set the background image to nil, and set the background color with alpha.

[ctrl.navigationController.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault]; 
ctrl.navigationController.navigationBar.backgroundColor = [UIColor colorWithRed:0 Green:0 Blue:0 Alpha:.5];

Upvotes: 8

Bouncing Bit
Bouncing Bit

Reputation: 358

According to the answer posted here it's possible to create a transparent UINavigationBar: How to draw a transparent UIToolbar or UINavigationBar in iOS7

However you want to create a semitransparent navigationbar. For that as far as I can tell you have to create a 1 px large image containing a black color with 50% opacity. Add this as backgroundimage for your Navigationbar.

This snippet should do the trick:

[[UINavigationBar appearance] setBarStyle:UIBarStyleDefault];
UIImage* sti = [UIImage imageNamed:@"EMT_SemiTransparent.png"];
[[UINavigationBar appearance] setBackgroundImage:sti forBarMetrics:UIBarMetricsDefault];
[[UINavigationBar appearance] setBackgroundColor:UIColor.clearColor];

Upvotes: 0

Garrett Taiji
Garrett Taiji

Reputation: 45

try setting key [View controller-based status bar appearance] to NO in your pList file as well.

i've run into some funkiness with the status bar not seeming to be affected by changes in code and this solved it for me.

reference: https://stackoverflow.com/a/18184831/2962193

Upvotes: -1

Nandha
Nandha

Reputation: 6776

Set the alpha value to make it transparent.

[[UINavigationBar appearance] setAlpha:0.5f];

Upvotes: -2

Related Questions