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];
Related
I have an UITabBar that needs to be coloured after initialization.
I use:
[[UITabBar appearance] setTintColor:secondaryColor];
[[UITabBar appearance] setBarTintColor:primaryColor];
[[UITabBar appearance] setUnselectedItemTintColor:[secondaryColor colorWithAlphaComponent:0.5]];
This works when the color are available at start time but when I try this after creation this doesn't work until another controller is pushed & poped on the navigation stack.. after that the tabbar is properly colored. How can I force this without push/poping another controller?
I tried setNeedsDisplay on the tabbar but it doesn't work.
I want remove border of navigation bar. I am using this code in AppDelegate.m
[[UINavigationBar appearance] setBackgroundImage:[[UIImage alloc] init]
forBarPosition:UIBarPositionAny
barMetrics:UIBarMetricsDefault];
[[UINavigationBar appearance] setShadowImage:[[UIImage alloc] init]];
and it works well. It removes border of navigation bar in every view controller.
But i have to remove it for few view controllers.
By placing this code in viewWillAppear of particular view controller, its not working.
Does anyone knows how to do it?
You should set the background image and shadow image of the navigation bar in your select navigations bars and not to use the appearance method. e.g.:
[self.navigationController.navigationBar setBackgroundImage:[UIImage new]
forBarMetrics:UIBarMetricsDefault];
I am working with themes in my app. Each theme comes with a custom navigation bar. As a default, I have applied a custom navigation bar in my AppDelegate:
[UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
UIImage *navBackgroundImage = [UIImage imageNamed:#"purplynav.png"];
[[UINavigationBar appearance] setBackgroundImage:navBackgroundImage forBarMetrics:UIBarMetricsDefault];
If I go to a specific Table View Controller in my app and in the viewWillAppear, I put:
if ([self.selectedTheme isEqualToString:#"Blur"])
{
UIImage *navBackgroundImage = [UIImage imageNamed:#"pastelpinknav.png"];
[[UINavigationBar appearance] setBackgroundImage:navBackgroundImage forBarMetrics:UIBarMetricsDefault];
}
The "pastelpinknav" suddenly gets applied to every single navigation bar in my app, even though I'm only setting it in this one Table View Controller.
How do I set it so that the navigation bar only applies to this one view controller when set, but is still set to default in the App Delegate when a theme is not set?
Thanks in advance!
You have to change again the navigationBar image in viewWillDisappear
UIImage *navBackgroundImage = [UIImage imageNamed:#"purplynav.png"];
[[UINavigationBar appearance] setBackgroundImage:navBackgroundImage forBarMetrics:UIBarMetricsDefault];
Because you are using [UINavigationBar appearance] it will commonly changes the UINavigationBar appearance.
From your view controller call:
[[UINavigationBar appearanceWhenContainedIn:[self class], nil] setBackgroundImage:navBackgroundImage
forBarMetrics:UIBarMetricsDefault];
Explenation:
This will change the foo color of the entire app:
[[UINavigationBar appearance] setFooColor:#"blue"]
In order to change appearance of specific container (i.e your view controller), you need to implement UIAppearanceContainer and then call (UIViewController already implements it):
[UINavigationBar appearanceWhenContainedIn:(Class<UIAppearanceContainer>), ..., nil]
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
Now I am trying to change UINavigationController background image with my custom Image.
I can change with following codes.
[navigation.navigationBar insertSubview:[[UIImageView alloc] initWithImage:[UIImage imageNamed:#"navController.png"]] atIndex:1];
So I got following pic. That pic is right and show the BarButton.
But when I go to the detailViewController , there is no BackButton. However I can tap without seeing it.
After I back to MainViewController , my UINavigationController Background is happening like following pic.
They are hiding my button. I'm thinking atIndex:1 is making this problem because Index 1 is above 0 and All button Index must be 0.
That's why all buttons are disappearing.
So how can I solve that problem? Please help.
Thanks for your help.
// not supported on iOS4
UINavigationBar *navBar = [purchaseNavController navigationBar];
if ([navBar respondsToSelector:#selector(setBackgroundImage:forBarMetrics:)])
{
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:#"brnlthr_nav.jpg"] forBarMetrics:UIBarMetricsDefault];
}
Try using the appearance proxy provided by apple
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:#"your_image"] forBarMetrics:UIBarMetricsDefault];
that will set it for the entire application or you can use
[[self.navigationController.navigationBar appearance] setBackgroundImage:[UIImage imageNamed:#"your_image"]];