I'm trying to set a custom shadow image for the navigation bar in my table views, but it's only showing in some views. I've created a super class to set the styles for my table views.
- (void)viewDidLoad
{
[super viewDidLoad];
// Set navigation bar background
[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:#"navigationbarbackground.png"] forBarMetrics:UIBarMetricsDefault];
// Set navigation bar shadow imag
[self.navigationController.navigationBar setShadowImage:[UIImage imageNamed:#"navigationbarshadow.png"]];
In the view I see at starting my app, no shadow is showed. But when I touch the [+] button in my navigation bar to open my 'add new item' table view, it does show a shadow.
Could someone point me in the right direction here?
you need to set custom backgroudImage for UINavigationBar, then the shadowImage can work.
The Appearance proxy should work.
Just call it somewhere (e.g. in your AppDelegate) upon startup.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[self customizeAppearance];
return YES;
}
- (void) customizeAppearance
{
// Set the background image for *all* UINavigationBars
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:#"navigationbarbackground"] forBarMetrics:UIBarMetricsDefault];
// Set the shadow image for *all* UINavigationBars
[[UINavigationBar appearance] setShadowImage:[UIImage imageNamed:#"navigationbarshadow.png"]];
//add other appearance stuff here...
}
However if you create a storyboard with multiple UINavigationController's in it and a bunch of segue's pushing navigation controller's you might get a corrupt view controller structure which might be the problem here.
Another possible issue might be the Clip Subviews option of a Navigation Bar somewhere in your nib file or you storyboard. Make sure it is turned off if you want the shadow (image)!
By the way, if you use imageNamed you don't need to include the file extension.
Try this !
[[UINavigationBar appearance] setShadowImage:[UIImage imageNamed:#"navbar-iphone.png"]];
Related
In my application i want to change the tab bar controller color,How to assign a custom color to the tab bar controller lik uinavigation bar in ios6?Can any one give me some refrences?
Put this on app delegate:
UITabBarController *tabBarController = (UITabBarController *) self.window.rootViewController;
tabBarController.view.tintColor = [UIColor redColor];
It's better than the first answer because it also changes the edit view tint color.
You can use the setTintColor option as described
[tabbarController.tabBar setTintColor:[UIColor greenColor]];
or you can set the background image
[tabbarController.tabBar setBackgroundImage:[UIImage imageNamed:#"tab_bg.png"];
if your TabBarController is defined int the AppDelegate you may need additional coding to access it.
First to set the background image
[[[[(UITabBarController *)[[(AppDelegate *)[UIApplication sharedApplication].delegate window] rootViewController]tabBar]setBackgroundImage:[UIImage imageNamed:#"tab_bg.png"]]]];
Second to set the tintcolor if required
[[[[(UITabBarController *)[[(AppDelegate *)[UIApplication sharedApplication].delegate window] rootViewController]tabBar]setTintColor:[UIColor redColor]]]];
dont forget to import your AppDelegate.h file.
You can use this call
tabbarController.tabBar.tintColor = [UIColor redColor];
To change only tabBar color, you can achieve by this:
tabbarController.tabBar.tintColor = [UIColor redColor];
But, for more, you need to create Custom TabBar and can do with it like color change, custom tabbar icon changes, etc.
Hope, it will be helpful to you.
Cheers.
Approach that worked for me (tested in iOS6) is:
[[UITabBar appearance]setTintColor:[UIColor redColor]];
in AppDelegate.h file in method application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions. Try this if it's still actual. I see the question still stays unsolved.
I have a MFMailComposeViewController that I'm presenting and I want to clear the image from the navigationBar.
On iOS 5, this works fine:
[self.navigationBar setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];
But on iOS 6, this has no effect. How could I do this?
Thank you!
You jus hide the navigation bar..
self.navigationController.navigationBarHidden = YES;
or
[self.navigationController setNavigationBarHidden:YES animated:animated];
I'm sorry, I have to answer my own question. I made an error: I had set the UINavigationBar app-wide by doing
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:#"bar01.png"] forBarMetrics:UIBarMetricsDefault];
which had the effect of causing all navbars to have the bar01. Removing this line made it so that the MFMailComposer navbar was the default color with no need to nil out the image.
I used custom navigation bar within my application,
// appdelegate.h
#implementation UINavigationBar(customNavBar)
- (void)drawRect:(CGRect)rect{
UIImage *navBarImage = [UIImage imageNamed:#"navBar.png"];
[navBarImage drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
}
#end
It works fine, but when I use a MFMailComposeViewController for sending an email, it appears with custom navigation bar. Here I don't want the customized navigation bar, I want it to be default.
How do I achieve this?
Here is the example of custom navigation bar for each navigation.
in your case you have to modify that code to your needs.
Change Navigation bar Background image on each navigation
When I receive a memory warning in my navigation based iPhone App the background image disappears in the previously allocated navigation controllers.
The background image is set as the background property of a UIView. This view is then added to the main window of the App delegate:
UIView *backgroundView = [[UIView alloc] initWithFrame: window.frame];
backgroundView.backgroundColor = [UIColor colorWithPatternImage:[[Utilities sharedManager] getImageWithName:#"Hintergrund2"]];
backgroundView.tag = 56789;
[window addSubview:backgroundView];
[backgroundView release];
[window addSubview:[navigationController view]];
[window makeKeyAndVisible];
After I received the memory warning message and pressed the back button of the navigation controller the previous navigation controller shows up the normal Apple gray background. I have to navigate back to my home screen and navigate forward to "reset" the background image.
Can anyone tell me why the background disappears? It is not because of the image, when I set the background to a standard UIColor like blackColor the background (color) also disappears.
Thank you in advance for your help!
regards
Phil
It is undefined what the OS does with stuff added directly to the main UIWindow in case of low memory situations.
Maybe consider using a simple UIViewController for the background? You will then at least get callbacks when there is a low memory situation.
First, you should probably add your controller to the window like this:
window.rootViewController = navigationController;
I haven't tested this, but perhaps you can set the background color of the window directly:
window.backgroundColor = [UIColor colorWithPatternImage:[[Utilities sharedManager] getImageWithName:#"Hintergrund2"]];
If that doesn't work, you'll need a better way to recreate your view state in low memory situations. The most standard way to do this is by defining the background in each xib, which is reloaded. Alternatively, you could catch the low memory warning and recreate as needed by seeing if your backgroundView has a superview.
Make sure that you are setting the calling self.view.backgroundColor = [UIColor clearColor]; in the view controller's - (void) viewDidLoad otherwise the window's image will not be displayed.
- (void) viewDidLoad
{
[super viewDidLoad];
self.view.backgroundColor = [UIColor clearColor];
...
}
My problem was that I set the view's backgroundColor when it is initialized
MyTableViewController *myTVC =
[[MyTableViewController alloc] initWithStyle:UITableViewStyleGrouped];
myTVC.view.backgroundColor = [UIColor clearColor];
and not in - (void) viewDidLoad.
In this situation, the UITableViewController's view's background color was set after it was initially created. However after a low memory warning, the UIViewController's that were not displayed have - (void) viewDidUnload called on them. That deallocate their views. Just before the UIViewController was to be displayed again, - (void) viewDidLoad was called and created a new view, but the view's background color was set to the default which is not clear.
Essentially i want to display a notification just beneath the UINavigationController, covering the area that would be occupied by the top most UIViewController's view. However i want the background image to extend upwards and partly cover the UINavigationBar
The finished product should hopefully look like the below
The trick comes in that i only want this to apply to certain views with the view Hierarchy, so attacking the problem by using [UIApplication keyWindow] might not be the best idea. Also i assume that by using views outside of the private UINavigationTransitionView won't be part of the view transition animation, leaving my view on top of the controller beneath when this one is popped.
The view of the topmost view controller doesn't help either, as it's frame is terminates at the base of UINavigationBar, meaning arrow won't overlap the UINavigationBar
Suggestions?
Thanks
Since it seems that you are facing the problem with Navigation Bar only as that will not allow to overlap the View.
This is tricky part....
Just use the Custom back button set the image over it in left of the Navigation bar Button
UINavigationBar *bar = [self.navigationController navigationBar];
UIButton *btn;
btn = [[UIButton alloc] initWithFrame:CGRectMake(5, 2, 100, 48)];
[btn setImage:[UIImage imageNamed:#"left.png"] forState:UIControlStateNormal];
btn.backgroundColor = [UIColor clearColor];
[bar addSubview:btn];
[btn release];
This is surely going to help you & solve all your Queries for the same ....