Use UIAppearance styling except in modal view controllers? - ios5

I customized the appearance of all my navigation bars by using the UIAppearance API introduced in iOS 5:
[[UINavigationBar appearance] setTitleTextAttributes:titleTextAttributes];
[[UINavigationBar appearance] setTitleVerticalPositionAdjustment:+2.f forBarMetrics:UIBarMetricsDefault];
[[UIBarButtonItem appearance] setTintColor:[UIColor lightTextColor]];
This works great for all my own navigation bars.
However, it also styles all system-provided navigation bars, such as when I modally display an MFMailComposeViewController (see screenshot below) or use the ABPeoplePicker.
Is it possible to define exceptions such as “don’t use this appearance when shown modally”?

take a look at appearanceWhenContainedIn option, this allows you to select which viewcontroller class the appearance applies to

Related

MPMediapickercontroller tab bar overlap with custom tab bar in iPhone

I can hide or unhide tab bar in navigation controller. But issue when I use presentModelViewController of MPMediapickercontroller, and even when hiding custom tab bar, it overlaps the tab bar of MPMediapickercontroller.
Please take a look at this image.
This is a default 'MPMediapickercontroller' presented.
I have been surfing to find this fix but with no success.
In MPMediapickercontroller its always present modally. so one solution for that is you have to use image which is same as tabbar of MPMediapickercontroller.
Here is that image. use without any border just white image thats it.
Now, below is my code.
In Viewwillappear method you have to set that image in tabbar appearance.
-(void)viewWillAppear:(BOOL)animated
{
[[UITabBar appearance] setBackgroundImage:[UIImage imageNamed:#"tabDefault"]];
[super viewWillAppear:YES];
}
Then whatever you want presentModelViewController of MPMediapickercontroller
in last you done all things then you have to use dealloc method to set Tabbar same as you required permanent.
-(void)dealloc
{
[[UITabBar appearance] setBackgroundImage:[UIImage imageNamed:#"tab2"]];
}
I solved my problem from this. hope you done it.

Mail Compose View Controller Navigation Bar [duplicate]

This question already has answers here:
Override UIAppearance property for MFMailComposeViewController
(3 answers)
Closed 9 years ago.
I am setting the appearance protocol to add a custom image for all my navigation bars. This is working as expected, but I do not want to change the appearance for the
MFMailComposeViewController's navigation bar.
How can I make this navigation bar, the default navigation bar?
[[UINavigationBar appearance] setBackgroundImage:[ApplicationStyle navigationBarImage] forBarMetrics:UIBarMetricsDefault];
The appearance proxy enables you to modify the appearance of the UI when it's contained in a specific class through the -appearanceWhenContainedIn method. You can set the image to nil to prevent it from being shown in the MFMailComposeViewController class as shown below.
[[UINavigationBar appearanceWhenContainedIn:[MFMailComposeViewController class], nil] setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];
According to this question, you need to change the appearance proxy before and after you present the modal MFMailComposeViewController in order to change its appearance back to how it was.
Override UIAppearance property for MFMailComposeViewController

appearanceWhenContainedIn not working as expected

I'm using iOS's UIAppearanceProxy to customize the look of my app.
In most of the app, I want the navBar to have one background image. In one specific section of the app, I want the navBar to have a different background image.
Here's what I'm doing in application:didFinishLaunchingWithOptions:
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:#"navbar_bg1"]
forBarMetrics:UIBarMetricsDefault];
[[UINavigationBar appearanceWhenContainedIn:[DiscoverViewController class], nil] setBackgroundImage:[UIImage imageNamed:#"navbar_bg2"] forBarMetrics:UIBarMetricsDefault];
I would like to keep all my appearance code in one place instead of overriding the navBar in a specific view controller.
Also helpful to know is that my app is structured with a TabBarController, where each tab controls a NavigationController which owns a subclassed ViewController, like DiscoverViewController above.
What am I doing wrong?
As you just stated, the navigation bar is not contained in the DiscoverViewController in your hierarchy; rather, both are contained in a navigation controller. One way to keep the appearance code centralized is to create an empty subclass of UINavigationController and instantiate that instead of UINavigationController in the relevant place (whether that's a nib or storyboard or just programmatically). Then, to style child elements, get their appearance proxy "when contained in" DiscoveryNavigationController or what have you. I've used this method with good results in the past.

iPhone iOS5 Storyboard change navbar appearance

I want my navbars to use black transparent appearance. In my non-storyboard apps, i could put this code in the AppDidFinishLoadingWithOptions :
[[UINavigationBar appearance] setTintColor:[AppColors navBarColor]];
[[UINavigationBar appearance] setBarStyle:UIBarStyleBlackTranslucent];
[[UINavigationBar appearance] setAlpha:0.7];
[[[UITableView appearance] backgroundView]setBackgroundColor:[AppColors tableViewBackgroundColor]];
[[[UITableViewCell appearance] backgroundView]setBackgroundColor:[AppColors tableViewCellBackgroundColor]];
Where would this code go if I'm using a storyboard? It appears that my controllers are loaded before the app finishes launching
Thank you!
This will continue to work with storyboards. The appearance class method returns a proxy object that defines style information for all created instances of that class.
Try putting it in the viewDidLoad method in your applications root view controller.

UIBarButtonItem tintColor with UINavigationController

I have a navigation controller with 2 UIBarButtonItems in my navigation bar. I want to change the tint color only for the one on the right. I have found a way in static to do that:
[[self.navigationController.navigationBar.subviews objectAtIndex:2] setTintColor:[UIColor redColor]];
The problem is when I push a controller into my navigation controller to display another view, when I come back to the root view where my right navigation bar button is supposed to have a custom color, the color of the button is back to its default. And when I click again on it, the app crashes. It says it cannot change the tint color, like if the index for this element in my navigation bar changed.
I have tried other technics found on the internet, but they all failed when I use the navigation controller and come back to the root controller...
Any idea?
Thanks!
Edit 1:
I would like a bordered style button in my UINavigationBar, with a red or green background color.
Regarding the other ways I found, it is pretty much a foreach loop of the views in the navigation bar, and if the view's kind of class is a button item then change the tintColor. It doesn't crash but it applies to all the UIBarButtonItem of my navigation bar (and I just want a specific button, the right one, not all of them). For example this tutorial is half working, my app crashes when coming back to the root view controller.
Digging into the subviews of the navigationcontroller.navigation bar wont fly with Apple, ...
the correct way to change the color of a UIBarButtonItem is to use a customView with the buttonitem. here is a link that explains...
UIBarButtonItem with color?
You simply create a segmented control with just one segment. Set its tint color as you like. You may also want to set its mode to momentary so it optically behaves like a button. Add the segmented control to the bar button item by using the initWithCustomView: initializer. That's how you typically create custom tinted buttons.
Example:
UISegmentedControl *cartControl = [[UISegmentedControl alloc] initWithFrame:CGRectMake(10,7,60,30)];
[cartControl setTintColor:[UIColor colorWithRed:0.35 green:0.47 blue:0.65 alpha:1]];
[cartControl addTarget:self action:#selector(cart:) forControlEvents:UIControlEventValueChanged];
[cartControl setSegmentedControlStyle:UISegmentedControlStyleBar];
[cartControl insertSegmentWithImage:[UIImage imageNamed:#"shopping_cart_white_small.png"] atIndex:0 animated:NO];
[cartControl setMomentary:YES];
UIBarButtonItem *cartButton = [[UIBarButtonItem alloc] initWithCustomView:cartControl];
[cartControl release];
[[self navigationItem] setRightBarButtonItem:cartButton];
[cartButton release];