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

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

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];

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];

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

Set the alpha value to make it transparent.
[[UINavigationBar appearance] setAlpha:0.5f];

Related

Customizing UINavBar with custom color and without hairline

I want to set my navigation bar to the same color as my UITableViewCell(s), while also hiding the pixel line between the navigation bar and the cells.
The code I've used, in the AppDelegate didFinishLaunchingWithOptions, is this:
[[UINavigationBar appearance] setBackgroundImage:[[UIImage alloc] init] forBarMetrics:UIBarMetricsDefault];
[[UINavigationBar appearance] setShadowImage:[[UIImage alloc] init]];
[[UINavigationBar appearance] setBackgroundColor:[UIColor colorWithRed:0.465639 green:0.763392 blue:1 alpha:1]];
It removes the pixel line and sets the Nav Bar's color.
However, it leaves the status bar as transparent and my table view appears in the status bar when I scroll down.
How can I add the color to the status bar as well?
Thanks!
If its a solid colour you could always use:
self.navigationController.navigationBar.translucent = NO;
To stop the content going behind the bar
And use the new barTint property
self.navigationController.navigationBar.barTintColor = [UIColor redColor];

Navigation bar keeps turning into gray despite changing it to white. Why?

I'm using this code to turn the "Back" button on a navigation bar to white, but it keeps making it gray.
[[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];
I also tried this:
[[UINavigationBar appearance] setTintColor:UIColorFromRGB(0xFFFFFF)];
I've also tried (I found it in another question):
[[UINavigationBar appearance] setTintColor:[UIColor colorWithWhite:1.0 alpha:1.0]];
None of them work! They keep making it gray! If I try red/black/green or another color, they work, but white keeps turning into gray.
Try it like this...
UINavigationController *controller= [[UINavigationController alloc]
initWithRootViewController:YourViewController];
controller.navigationBar.tintColor = [UIColor whiteColor];

UINavigationBar color has changed after upgrading to latest Xcode

Recently I've updated my Xcode IDE to the latest to have iOS 7.1 SDK. For some reason, after recompiling my app with the new Xcode I get this wired UINavigationBar background colour.
I'm using storyboard to push the secondary view controller from home screen. The secondary view controller is a static table of settings, also built using storyboard, and contains the following code in its viewDidLoad method:
[self.navigationController.navigationBar setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];
self.navigationController.navigationBar.shadowImage = nil;
I haven't done any other changes to this screen or any other screens in the app.
This is how it used to look like before:
This is how it is look like now:
Does anyone have any idea what could have caused this?
Cheers,
EDIT: #Leo Natan -
When I'm trying to set the color myself, for example, by replacing this line:
[self.navigationController.navigationBar setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];
with this line:
[self.navigationController.navigationBar setBackgroundColor:[UIColor redColor]];
I get this: the red color applied only on the header without the status bar, what can I do?
Latest Xcode comes with iOS7.1 SDK, in which Apple once again changed how the color is calculated. You will have to play again with your color to achieve a similar look in iOS7.1.
Maybe you should take another approach. Use the Appearance Proxy in the - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions. Thats how I do it:
//Navigationbar
[[UINavigationBar appearance] setBarTintColor:lightOrangeColor];
[[UINavigationBar appearance] setBackIndicatorImage:[UIImage imageNamed:#"navbarAssets-backArrow-iOS7"]];
[[UINavigationBar appearance] setBackIndicatorTransitionMaskImage:[UIImage imageNamed:#"navbarAssets-backArrow-iOS7"]];
[[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];
[[UINavigationBar appearance] setTitleTextAttributes: #{NSForegroundColorAttributeName : [UIColor whiteColor]}];

iOS7 No barTintColor on launch

When I open my app, during the new animation of io7, the navigation bar is transparent and black without the color that I chose for barTintColor until the app loads. Why is this?
This was happening because the self.navigationController.navigationBar.translucent was YES. Setting it to NO fixed the problem. It also changes the color of my barTintColor and I had to adjust accordingly just FYI
UIColor *NavBarTintColor = [UIColor colorWithRed:0.223 green:0.223 blue:0.223 alpha:1.000];
[self.navigationController.navigationBar setTintColor:[UIColor lightGrayColor]];
[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:#"Image.png"] forBarMetrics:UIBarMetricsDefault];
At ios7, I use below code to set the color and it worked for me:
myNav.navigationBar.barTintColor = [UIColor redColor];

UIAppearance and UINavigationBar controller

I have background images for my UIBarButtonItems and my UINavigationBar. I am trying to use UIAppearance to customize all of them with the following:
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:#"navbar.png"] forBarMetrics:UIBarMetricsDefault];
[[UIBarButtonItem appearance] setBackgroundImage:[UIImage imageNamed:#"navbar_btn.png"] forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
and it works very well. The only problem is the default back buttons on the UINavigationBar still use the standard iOS background color/image. When I set the TintColor on [UINavigationBar appearance] it will change the colors, but that only takes a UIColor.
Is it possible to either set the default navigation back button image (without manually changing every viewcontroller) or convert an image into a UIColor?
Thank you!
UPDATE: ANSWER IS BELOW
Apparently UIBarButtonItem has a separate function for the backbutton customization. I had to create another image for the back button based off navbar_btn.png and set it using:
[[UIBarButtonItem appearance] setBackButtonBackgroundImage:backButtonImage forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
Apparently UIBarButtonItem has a separate function for the backbutton customization. I had to create another image for the back button based off navbar_btn.png and set it using:
[[UIBarButtonItem appearance] setBackButtonBackgroundImage:backButtonImage forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];