I know this may be a pretty open ended question, but I am trying to set a different color to my navigation bar using this:
self.navigationController.navigationBar.tintColor = [UIColor greenColor];
And from some reason in one view controller I do get green color and in another one I am not getting the green color. I am calling this in viewdidLoad.
Is there something that could override that? (I am not overriding drawRect).
Happy to provide any code if necessary, but this really puzzels me.
Thanks!
Maybe you're using a second UINavigationController instance in one of your view controllers?
That could happen if you're presenting a UIViewController modally (UIViewController method presentModalViewController:animated:).
If you're presenting a UIViewController that's not on the same "navigation stack" (managed by the original UINavigationController), you would have to apply the same tintColor to its UINavigationBar.
Related
this is probably quite simple.. but I don't know what's the best practice here.
i have a tabbarcontroller with 4 tabs, 3 of them should be a UINavigationController, the other one should also have the UINavigationBar to it but should not be a nav controller itself.
Now i want to give the UINavigationBar a tint color and an action button. I'd like to do this in the interface builder.
The navBar should always be the same one and i only want to create it once.
But where exactly would i do it? Would i create a .xib file with only the UINavigationBar in it and somehow link to that?
I'm very confused here, most tutorials only discuss the navBar for ONE navController but in my case i need the same bar for different ViewControllers..
NavBar comes with the navigationController or can come seperate. It is a subclass of UIView.
You cannot simply share your navBar with all controllers and the non-navigationController. I mean one instance of a navbar. You cannot even set the navbar for a navigationController. It is only readable.
In my understanding you are trying to make the navbar look the same in every controller, am I right?
So you can for instance subclass a UINavigationController and set it up as you want in the init method and init this subclass to add it to the view.
But what about the non-UINavigationController navBar?
Well, that's easy: Simply add your subclassed navigationController to that tab. You don't have to use it as NavController. You simply can add views to his view as to a standard ViewController.
Here it is.
I have a UINavigationController inside a UITabBarController.
Is there a way to set the navigation bar translucent??
I tried, programmatically, to set it like this:
navigationController.navigationBar.translucent = YES;
but nothing changes.
I even tried to log the translucent value and it is actually YES but the bar is still completely opaque.
The view behind the nav bar covers the full screen, i can even see it under the (translucent) status bar. I really don't understand.
All this happens only if the nav controller is inside the tabbar controller.
EDIT:
Guess what? It was xcode screwing up my nib file ...
I recreated the xib from scratch and it works as expected.
Thanks anyway
You are setting the wrong property:
self.navigationController.navigationBar.barStyle = UIBarStyleBlackTranslucent;
I am also trying to change navigation bar style for my UITabBarController based app recently using XCode 4.2.1. The code given by Zebs is wrong in this context. If you are working with navigationController that you create by yourself, then it'd be ok, but the thing is, the navigationController created by the UITabBarController is created by UITabBarController hence the correct code is:
self.moreNavigationController.navigationBar.barStyle = UIBarStyleBlack;
Note we use moreNavigationController instead of just navigationController. Hope that helps everyone who is facing the same problem.
I can't change the color of my UINavigationBar.
I've put a navigation bar manually using Interface Builder, but I can't change its color to the following settings. I'm putting this code on ViewDidLoad (the code works fine with other classes on my app, except this one, where I'm using the UINavigationBar via IB):
self.navigationController.navigationBar.tintColor = [UIColor colorWithRed:0.122 green:0.467 blue:0.255 alpha:1.00];
Any suggestions? Thank you!
Did you check that you have the navigation bar connected through IB? as in, Did you declare a IBOutlet UINavigationBar in your controller, and then connected the navigation bar in IB to it's outlet?
You might not be on the navigation controller stack at this point. Trying putting it in viewWillAppear:
EDIT: You can check this by seeing if self.navigationController.navigationBar returns nil.
I am trying to use the UINavigationController object's built-in UIToolbar object in my iPad application, but I want it to be displayed on top of the view instead of the bottom, which is where it defaults.
I am also hiding the UINavigationController object's Navigation Bar.
In order to make this work, I had to write the following code:
navigationController.navigationBarHidden = YES;
navigationController.toolbarHidden = NO;
navigationController.toolbar.frame = CGRectMake(0, 0, 768, 44);
This solution works with one exception: when the application Enters Background and Becomes Active again, the Toolbar is always repositioned on the bottom of the view.
I've tried moving the code from viewDidLoad to viewDidAppear:animated, and it still behaves this way.
First, is there any better way to approach this, and if not, how can I stop the Toolbar from being repositioned?
I've also instead decided to use my own UIToolbar object and add it to each view via a custom Base UIViewController class' viewDidLoad. However, this causes the Toolbar to animate when each view is pushed or popped because it is actually part of the view, which just seems "hokey".
Any ideas on possible solutions?
Thanks everyone!
It says in the documentation under UINavigationController's toolbar property that:
Access to this toolbar is provided solely for clients that want to present an action sheet from the toolbar. You should not modify the UIToolbar object directly.
This is sort of hackish, but you could make a UIToolbar yourself and add it directly to the window (i.e. over the navigation controller.)
You can use the category below to modify the UIToolbar class to achieve what you're after.
#implementation UIToolbar (setCenter)
-(void)setCenter:(CGPoint)center
[super setCenter:CGPointMake(384, 22)];
}
#end
The toolbar has limited functionality when used with a UINavigationController. It only provides a convenient way to manage the actionsheet in the toolbar.
From the docs: "Access to this toolbar is provided solely for clients that want to present an action sheet from the toolbar. You should not modify the UIToolbar object directly."
The solution I would use is to create a subclass of UIView with convenience methods to manage your actionsheet and any other custom functionality you need. This custom view can be shared across all views in the UINavigationController and placed where ever you like in the parent view. This will give you ultimate control of your custom top placed toolbar.
I saw this amazing transition in an app: when the user clicks on an item in the tableview and it "drills down" the transition is done "on top" of a background. That is the background image is static and just the actual tableview and whatever is presented after pressing something is moving (from right to left as usual).
How is this layered tableview transition done? Anyone knows?
(the app is "Munch-5-a-day" in the info-view)
Endemic gives you the right direction. Another way can be view controllers with transparent background and then customize UIWindow.
UINavigationController is a subclass of the standard UIViewController class, so it inherits the view property of UIViewController. I would imagine that the background image transition consists of two important steps:
Assign a UIImageView containing the desired background image to the view property of the NavController
Set self.view.backgroundColor = [UIColor clearColor] in each ViewController, most likely in the viewDidLoad method.
I'm currently unable to test this, but it should work.
Reference: UINavigationController Class Reference