Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Translucent and custom image in Navigation Bar iOS 7

Tags:

ios

iphone

ios7

In iOS 6 i used this method

 - (void)drawRect:(CGRect)rect 
{
// Drawing code
UIImage *image = [UIImage imageNamed: @"nav_bar.png"];
[image drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
}

But when i use this in iOS 7 it only covers the leaving the status bar empty, i already tried using a bigger image, it doesnt work.

But most importantly i want to use the translucent option in the navigation bar, is it compatible translucid and having a custom image in the nav bar?

like image 421
ElioMB Avatar asked Dec 02 '25 04:12

ElioMB


2 Answers

If I've understood your question correctly (apologies If I haven't), you want to extend the navigation background image to be behind the status bar too.

You can try this code:

[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"nav_bar.png"] forBarMetrics:UIBarMetricsDefault];

in order for the nav_bar.png image to be behind the status bar too, you need to add 20px to the height of the image. The height of the Nav Bar is 44px.

Basically, nav_bar.png needs to be a width of 320px and ad height of 64px. It will then be behind the status bar.

I would advise that with iOS 7, you don't use flashy graphics (as Yanchi said) and just use a simple colour. Either choose the white or black default ones, or use the following code to change the colour tint of the Nav Bar:

self.navigationController.navigationBar.barTintColor = [UIColor #Choose a colour#];

You replace #Choose a colour# with a UIColor such as blueColor or redColor. You can also programmatically set the translucency to YES.

self.navigationController.navigationBar.translucent = YES;

To answer your last question about whether you can make the Nav Bar translucent, like Yanchi said, you'll only be able to change the actual image's alpha. If you want the blur effect (iOS 7 style) it doesn't work. I've tried and there doesn't seem to be a way. It only works with solid colours (using the UIColor code I mentioned).

Hope that helps.

like image 116
Invalid Memory Avatar answered Dec 04 '25 17:12

Invalid Memory


Here is the Best Article:

http://www.appcoda.com/customize-navigation-status-bar-ios-7/

like image 42
Fury Avatar answered Dec 04 '25 18:12

Fury