Question

On appDidFinishLaunchingWithOptions, I tint my entire app red with the following code.

self.window.tintColor = [UIColor otfRedColor];

This works perfectly, and when my app loads, all the navigation bar items are red. A is my root view controller.

I have 3 view controllers, a, b, and c. A pulls up a modal presentation view sheet of b which pulls up a full modal view of c. When C is pulled up, the bar button items on navigation bar are all tinted gray, this shouldn't be happening because I didn't alter any tint or color in any way after the app delegate tinted the window. I then use

[self.presentingViewController.presentingViewController dismissViewControllerAnimated:YES completion:nil];

to dismiss VC c and b, but now my ENTIRE app is tinted gray. I haven't used any tint code at all since the app delegate, why does this happen? When I go from A to B again, that navigation bar items are still red???

Code to pull up view controller B from A:

AthleteAdd *addAthlete = [self.storyboard instantiateViewControllerWithIdentifier:@"addAthlete"];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:addAthlete]; 
addAthlete.delegate = self;
navigationController.modalPresentationStyle = UIModalPresentationFormSheet;
[self presentViewController:navigationController animated:YES completion:nil]; 

Code to pull up C from B:

    MedicalReleaseVC *medRelease = [self.storyboard instantiateViewControllerWithIdentifier:@"showMedRel"];
    medRelease.delegate = self;
    [self presentViewController:medRelease animated:YES completion:nil];

Does anyone know why this happens, or have an idea? I have tried tinting the third view controller as red 3 separate ways and it still remained gray, then when everything is dismissed my entire app is gray. Please help!!

EDIT:

If it helps, the way I solved this problem was by setting the following in my appdelegate.m

 self.window.tintAdjustmentMode = UIViewTintAdjustmentModeNormal;
Was it helpful?

Solution

I think this is a bug in iOS7's handling of tintAdjustmentMode when opening and closing sheets and popovers. I've seen this bug happen in Apple's native mail app, where the bar button items become gray, or conversely, they no longer turn to gray once a popover shows up.

To debug this further, I suggest subclassing one of your views (or the window directly) and implementing tintColorDidChange. Log the value of tintAdjustmentMode there. I fear this is what is causing your gray tint issues.

One solution would be to force UIViewTintAdjustmentModeNormal but this would have the effect of no dimming when opening a popover or a sheet.

OTHER TIPS

I had to put

[[[UIApplication sharedApplication] keyWindow] setTintAdjustmentMode:UIViewTintAdjustmentModeNormal];

in my viewDidLoad to solve this issue. But as mentioned in other answers, it does have the adverse effect of not dimming the bar button items when a popup is up.

I set this at the appearance proxy level.

UINavigationBar.appearance().tintAdjustmentMode = .normal

Just put

self.view.tintAdjustmentMode = UIViewTintAdjustmentModeNormal;

in your viewDidLoad and your colors are back to normal.

There is definitely a bug. I noticed that when the popover does dim the window when it appears but after I change the keyWindow.tintAdjustmentMode manually (for custom views & modal view controllers), the popover will stop dimming even though I set the keyWindow.tintAdjustmentMode back to automatic.

When a popover is shown, the main view's TintAdjustmentMode is set to Dimmed. This should be reversed when the popover is closed, but when you navigate to a new screen from the popover, it doesn't happen for some reason.

I fixed this in the UIViewController being displayed as the popover - override the ViewWillDisappear method and set the TintAdjustmentMode on the main view controller's view back to Normal. (In Xamarin, I used UIApplication.SharedApplication.KeyWindow.RootViewController.View.TintAdjustmentMode = UIViewTintAdjustmentMode.Normal with a few checks for nulls along the way.)

Another solution is to NOT set the window tintColor and instead use appearance proxies where appropriate and set tintColor programmatically (or in Interface Builder) everywhere else. This appears to be safer than setting the global window tintColor, which elicits strange behavior especially after modals, system alerts, and action sheets dismiss.

Remove this:

self.window?.tintColor = UIColor.redColor()

Add these:

UINavigationBar.appearance().barTintColor = UIColor.redColor()
UINavigationBar.appearance().tintColor = UIColor.whiteColor()
UISegmentedControl.appearance().tintColor = UIColor.orangeColor()
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top