UI navigation bar custom background iPhone SDK - ios

I have customized the UINavigationBar of my app with a texture. Here is my code:
if ([[UINavigationBar class]respondsToSelector:#selector(appearance)]) {
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:#"MYIMAGE.png"] forBarMetrics:UIBarMetricsDefault];
}
The code works but I want to reduce the size of my texture how to do that?

I recommend that you resize or crop the image before you set it as appearance to the UINavigationBar. Here are two SO links to do that
Crop UIImage
Resize UIImage

Related

xcode remove custom navigation image in pickerview galley

I added the following code in the appDelegate to achieve custom background images for the navigation bar.
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:#"Nav-Bar_01.png"] forBarMetrics:UIBarMetricsDefault];
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:#"Nav-Bar_02_alter.png"] forBarMetrics:UIBarMetricsDefaultPrompt];
However, I want to exclude the native gallery pickerView from this background.
Is there any way to do so without applying the background on each navigation bar alone, but keeping the same code in the appDelegate ?
I ended up placing a background image for every navigation controller instead of placing it in the App Delegate. The background was then not applied on the pickerView.
[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:#"Nav-Bar_01"] forBarMetrics:UIBarMetricsDefault];

How to make a custom UIView to combine with UINavigationBar make it looks as one

As you can see below, the three buttons: STORE,AREA and All. These buttons looks like the UINavigationBar and them are combined together. I tried in storyboard, I added a custom UIView and try to set it's colour match the UINavigationBar background color. But it always has differences, and I can see the border line between UINavigationBar and the custom UIView. How to make a UIView to combine with the UINavigationBar to make it all looks like they are combined.
iOS 7 has shadow next to the navigation bar. Try below to remove that shadow:
if (IS_IOS7) {
[[UINavigationBar appearance]setShadowImage:[[UIImage alloc] init]];
}
You can change the navigation and status bar background only in iOS7. For this, you can use
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:#"nav_bg.png"] forBarMetrics:UIBarMetricsDefault];
The size of the nav_bg.png should be 320*64 px
If you want to simply change the color of navigation bar you can use
[[UINavigationBar appearance] setBarTintColor:[UIColor blueColor]];

iOS 7 navigationBar and iOS 6 navigationBar show different background image

I try to set background image to navigationBar I use blow code
[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:#"pp_Header.png"] forBarMetrics:UIBarMetricsDefault];
My image height is 120px
In iOS6 navigationBar height 120px but in iOS7 shows only 68px but i need to show 120px,
similarly Tool bar also having same problem
[pad_por_Toolbar setBackgroundImage:[UIImage imageNamed:#"Logo_bottom.png"] forToolbarPosition:UIToolbarPositionAny barMetrics:UIBarMetricsDefault];
how to solve this ?

Drawing in custom UINavigationBar, attached to top

I have a subclass of UINavigationBar. It's barPosition is UIBarPositionTopAttached.
Than I override -(void)drawRect:(CGRect)rect in my subclass. The rect, that comes as parameter, has always 44 px height, and I can draw only inside this rect. So, I can't perform drawing over the status bar and it has default look. If I comment -drawRect out, than it looks as expected, navigation bar and status bar look as a whole and have 64 px height. Is there a way to achieve this effect with having overrided -drawRect: in subclass of UINavigationBar?
I had a the issue of a custom UINavigationBAr with a background image which would not appear under the translucent Status Bar on iOS 7 when I was adding the image in drawRect.
After moving the background image to the ViewControllers viewDidLoad Method, the background image then appeared under the Status Bar
-(void)viewDidLoad
{
if (UI_USER_INTERFACE_IDIOM() != UIUserInterfaceIdiomPad)
{
UIImage *image = [UIImage imageNamed:#"nav-bg-ipad.png"];
[self.navigationController.navigationBar setBackgroundImage:image forBarMetrics:UIBarMetricsDefault];
}else{
UIImage *image = [UIImage imageNamed:#"nav-bg-iphone.png"];
[self.navigationController.navigationBar setBackgroundImage:image forBarMetrics:UIBarMetricsDefault];
}
// do your other stuff now …
Hopefully this helps

transparent image in UINavigationBar

i have made a simple design in photoshop
when i tried to put it in Xcode i had some problems with NavigationBar
i used this code to change the UINavigationBar background image (a PNG transparent image):
UINavigationBar *navBar = [[self navigationController]navigationBar];
[navBar setBackgroundImage[UIImageimageNamed:#"navBar2.png"]forBarMetrics:UIBarMetricsDefault]
everything works fine but the problem is that the image appears in the navigationBar without transparency.
please someone help me to fix the transparency issue i search everywhere without any satisfied answer
NB! Im using IOS 5
You might try setting the navigation bar to translucent.
[navBar setTranslucent: YES];
Do you have it in your Storyboard? Try change the style of your navigation bar into black translucent.
What you can do is set the background color of the view of the navigationController the same as the backgrouond color of the main view.
//Set your view's background color
[self.view setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:#"view_background"]]];
//Set your custom image for the navigationController
[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed: #"navigation_bar_image"] forBarMetrics:UIBarMetricsDefault];
//And then set the background color of the navigationController the same as the one of the view
[self.navigationController.view setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:#"view_background"]]];
[self.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
[self.navigationBar setShadowImage:[UIImage new]];
[self.navigationBar setTranslucent:YES];
And make sure you set up tint color to default.

Resources