Customizing navigation bar without affecting other view controllers in hierarchy - ios

I have a navigation bar customization problem to overcome, hopefully someone has wanted this same behaviour before.
In my navigation stack there are specific view controllers that I want to have a totally transparent navigation bar, I use this code to do it:
// Make navigation bar transparent
[self.navigationController.navigationBar setBackgroundImage:[UIImage new]
forBarMetrics:UIBarMetricsDefault];
self.navigationController.navigationBar.shadowImage = [UIImage new];
self.navigationController.navigationBar.translucent = YES;
self.navigationController.view.backgroundColor = [UIColor clearColor];
The problem is when I 'pop' back to my root view controller its navigation bar is transparent now too, and I don't want that. I need a way to only customize the nav bar in a specific view controller without messing it up totally for other view controllers.
Note: UIAppearance whenContainedIn will not work, and this is currently styled in viewDidLoad.

You can apply to the new style in viewWillAppear and revert to old or default style in viewWillDisappear or viewDidDisappear or viewDidUnload' whichever suits your app.

I guess that in your case you could use the method appearanceWhenContainedIn
of the UIApparence protocol.
This would allow for a per container control of the UINavigationBar appearance.

Related

How to apply styles on Google Places Autocomplete UI (full-screen) control on iOS

I've added the Google Places Autocomplete UI control in full-screen mode in my iOS application. Is there any way i can change the navigation bar's background color/tint color in this control?
I have also tried adding a new view controller in my application in an attempt to have better control on the styling. In this new view controller I have my navigation bar with the styles i want, and then added a UISearchController positioned at the top of the view (below the navigation bar). I linked this search controller with a results controller as described in the API docs here:
https://developers.google.com/places/ios-api/autocomplete#add_a_results_controller
However, as soon as i start typing something in the search bar, the results view hides the navigation bar.
I've also added the below code (again as described in the API docs), but it doesn't help either:
self.navigationController.navigationBar.translucent = NO;
_searchController.hidesNavigationBarDuringPresentation = NO;
// This makes the view area include the nav bar even though it is opaque.
// Adjust the view placement down.
self.extendedLayoutIncludesOpaqueBars = YES;
self.edgesForExtendedLayout = UIRectEdgeTop;
Any help will be greatly appreciated!
UPDATE: I think the Autocomplete control only works properly when used in a navigation controller based app. I didn't have one. Now that I've added the navigation controller, the global styles for navigation bar and status bar which i had already defined in app delegate seem to affect the autocomplete modal as expected. The other issue where the navigation bar would get hidden completely as soon as i typed anything in the search box seems to have been fixed as well with the inclusion of navigation controller.
With the latest release of the Autocomplete control (1.11.1, run pod update in your project to make sure you have the latest version) you can tint the navigation bar in a GMSAutocompleteViewController using the appearance proxy, for example:
[[UINavigationBar appearance] setBarTintColor:[UIColor greenColor]];
This should work whether or not you're using navigation controllers elsewhere in your app.

How to not change appearance of one class using UIApperance in iOS?

I am using the theme concept to change UI appearance in my app.I am using multiple themes.I want to change the color of navigation bar of each view controller but except RegisterViewController.So how can i do this?
I have tried following code
[[UINavigationBar appearance]setTintColor:[UIColor redColor]];
[[UINavigationBar appearanceWhenContainedIn:[RegisterViewController class] ,nil]setTintColor:[UIColor blueColor]];
You have the right idea, but the problem is that the navigation bar is not contained in RegisterViewController. It is contained in a UINavigationController.
In other words, if you have one navigation controller and many view controller children, and you want the navigation bar tint to be different for some of those children and not others, you can't do that using the appearance proxy, because in every case it is the same navigation controller and the same navigation bar. There is no distinction to draw.
So you'll have to do it some other way. For example, set up the navigation controller's delegate to change the navigation bar's tint depending on what view controller is coming to the front.

How to change the background of the navigation bar of a single view?

I have an application with multiple views and the main navigation bar has a background defined in AppDelegate.m . I want one of these views to have different background.
I've tried to embed the whole view in a navigation controller but with no luck. Also I've tried to change the background from the view controller class but with no luck.
If you can share the code that would be really helpful. Below might help
[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:#"image"] forBarMetrics:UIBarMetricsDefault]

Change NavigationBar Tint/Colour to different values for each ViewController in a Navigation Stack

Ok, here's a weird problem I can't seem to figure out, and doesn't seem to addressed in any of the answers here, at least as far as I can find...
I have a Navigation Controller with 4 Push Segues into new ViewControllers.
And I want to have the appearance of the Navigation Bar to be different colours for each View.
What I am seeing is that it is getting overridden on my first entry into a VC in the stack, and then I am unable to update it from then on.
In my Presenting VC I do this (to make the Nav Bar clear/invisible)
[self.navigationController.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
self.navigationController.navigationBar.shadowImage = [UIImage new];
[self.navigationController.navigationBar setBackgroundColor:[UIColor clearColor]];
Then in my pushed VC, I change the background color to a different color...
[self.navigationController.navigationBar setBackgroundColor:bgColor];
When I press back to go into the presenting VC, the color from the pushed VC persists...
Any ideas ??
Oh. Dumb mistake, but posting answer here for the community.
My NavBar code was in viewDidLoad, which of course never gets called again if it is the presenting ViewController in a NavigationController...
Moving the code to viewWillAppear fixed it.
breakpointsToTheRescue !

UINavigationController transparent for UITableView underneath

I have a UINavigationController handling then navigation in my app. I would like the navigation bar to show the contents of the UITableView as I scroll up.
I can't seem to get it to be transparent. I have it set to translucent
self.navigationController.navigationBar.translucent = YES;
But still nothing. I'd like to add color, but I'll worry about that later. I've tried creating a subclass of UINavigationController and specify
self.navigationBar.backgroundColor = [UIColor clearColor];
self.navigationController.navigationBar.translucent = NO;
But again, no luck. This is what my interface builder looks like...
And this is what it looks like when I scroll the text up under the nav bar. Any suggestions?
Alright, I figured out a (seemingly simple) solution.
If you're using a UINavigationController to add a UINavigationBar to each of your views, this will work for making a transparent navigation bar.
Select the Navigation bar in your UINavigationController
Then, in the inspector bar (on the right), select "Clear Color". Tada! I'm a bit embarrassed I didn't try this sooner. Hopefully this will save someone else lots of time.
Try using a UITableViewController embedded in a UINavigationController, instead of a UIViewController. It'll adjust the insets for the iOS7 live blur automatically, so that the list content will show up under the Toolbar/NavigationBar on scroll.
I can't really make it out from your screenshot, but you can disable 'Hide Toolbar' in the parent NavigationController. You then don't have to add it separatly.

Resources