How to not change appearance of one class using UIApperance in iOS? - 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.

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 link customized navigation bar to navigation controller?

I created a normal view controller with a customized navigation bar. Later I changed my mind to embed the view controller into a navigation controller. And I noticed that embedding the view controller into a navigation controller will create another navigation bar!
As the image show:
I am wondering if there is a way to replace the navigation bar created by navigation controller with my own customized bar?
Or, if it's not possible, is there a way to configure the new navigation bar? Because for some reason it's not shown in my interface builder.
You have 2 solutions
Hide the system navigationbar using below code so it was display your custom navigation.
self.navController.navigationBarHidden = YES;
Customize the system navigation bar with its background color, back button and title text color. For this you can refer a below links which provide you detail of its
http://www.appcoda.com/customize-navigation-status-bar-ios-7/
You can change the color and buttons of the UINavigationBar provided by the system and make it look like yours.

Seperation between navigation bar and table view disappear

I am creating an app with a navigation bar and a table view. For some reason, the navigation bar lacks its separator between it and the table view. In the Interface builder, it looks like it does have it. However, when I run my app in the simulator (or on device), the separator disappears. Why?
Edit: Here's a better picture of my storyboard as per requested.
You have to choose your first view controller and from top menu you must select Editor -> Embed In -> Navigation Controller This is how you add Navigation Controller to a View Controller.
Also you have to use delegation for passing data back from the pushed view controller.
Do you set the shadow image for the navigation bar? Like this:
[[UINavigationBar appearance] setShadowImage:[UIImage imageNamed:#"ShadowImage"]];
If you set, try to remove.

Customizing navigation bar without affecting other view controllers in hierarchy

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.

Navigation bar style in popover view controller

In iPhone SDK 4.2.3, use default Split View template to cook-up a dummy application.
In landscape mode, the master view uses default navigation bar style. In portrait mode, the master view uses black navigation bar style inside the popover. How can i change the bar style/tint color to make it consistent for both views?
I've tried to do this in split view delegate method, but it doesn't work.
pc.contentViewController.navigationController.navigationBar.barStyle = UIBarStyleDefault;
pc.contentViewController.navigationController.navigationBar.tintColor = [UIColor redColor];
I've also tried to explicitly set the navigation bar style in the master view controller class, but that doesn't seem to have any impact as well.
After playing around, i can safely say that it's not possible.

Resources