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 ?
Related
I am facing issue in margin of right bar button item title.
From iOS11 background image is overlapped means it is not properly right aligned.
It was working pretty good till iOS 10.
Code snippet:
UIBarButtonItem *rightItem = self.navigationItem.rightBarButtonItem;
[rightItem setBackgroundImage:[UIImage imageNamed:IMAGE_NAVIGATION_NEXT_BUTTON_DISABLED_iOS7]
forState:UIControlStateDisabled
barMetrics:UIBarMetricsDefault];
[rightItem setBackgroundImage:[UIImage imageNamed:IMAGE_NAVIGATION_NEXT_BUTTON_iOS7]
forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
rightItem.title = #"Next";
Before iOS11 it was working like this
When I set NavigationBar to translucent, I expect that the NavigationBar will not has a shadow line under it, and StatusBar has the same background of the view's background
I code like this:
[self.navigationController.navigationBar setTranslucent:YES];
[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:#"translucent_image"] forBarMetrics:UIBarMetricsDefault];
self.navigationController.navigationBar.shadowImage = [UIImage new];
They work perfectly on 5.5 inch iPhone like iPhone6 Plus and iPhone 6s Plus, But when run on the smaller iPhones like iPhone 6s and iPhone 5s, I get a bug like problem, The StatusBar turn into black! They are the same code on iOS 8.2, iOS 8.3 and iOS 9.2, The only difference is the screen!
I try to change the BarMetrics from UIBarMetricsDefault to UIBarMetricsCompact or UIBarMetricsDefaultPrompt to fix this problem, finally the StatusBar work well but the shadow line come out in all iPhones!
[self.navigationController.navigationBar setTranslucent:YES];
[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:#"translucent_image"] forBarMetrics: UIBarMetricsCompact];
self.navigationController.navigationBar.shadowImage = [UIImage new];
so strange! is this a bug of iOS?
Try changing your code to
[self.navigationController.navigationBar setShadowImage:[[UIImage alloc] init]];
[self.navigationController.navigationBar setBackgroundImage:[[UIImage alloc]init] forBarMetrics:UIBarMetricsDefault];
This works for me (i.e. I don't get the shadow)
Hi I have navigationBar with image in ios 7 [xcode 5].
When I run my application my navigationBar auto be blur.
I want to chenge it to regular [no blur].
my code:
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:#"nav_bg.png"] forBarMetrics:UIBarMetricsDefault];
I try add this code but the apps crash:
[[UINavigationBar appearance] setTranslucent:NO];
What need I do to make all my navigation bars in app to regular?
thank
If you are using storyboard you can set it here
If you need to set it in code use
self.navigationController.navigationBar.barStyle = UIBarStyleBlackOpaque;
in your viewDidLoad
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
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.