Reputation: 5089
In my app, I have a window tintColor that sets everything to be tinted red. a user presses a bar button item (red items) on the root view controller and it presents a UIModalPresentationSheet with a navigation bar (red nav items). Upon pressing a button on that navigation item, it pulls up a full Modal View, now this modal view also has a navigation bar but all the navigation items are gray; they are usable, and still run the correct function, but their color is gray. Any idea why? At first I tried doing this programmatically with gray buttons, then I did it through storyboarding and tinted the nav items directly in the scene and they looked red, yet at launch, they were grey on the Modal View. Can anyone tell me why??
Here is how the modal view is presented:
- (void)barButtonItemPressedOnUIModalPresentationSheet {
asdfVC *viewController = [self.storyboard instantiateViewControllerWithIdentifier:@"showAsdf"];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
[self presentViewController:navigationController animated:YES completion:nil];
}
The weird thing is that I set the nav tint, the button tint, even the view tint in the correct VC class, yet it seems to completely ignore it. Could it be because I set a navigation bar on it before presenting it?
Upvotes: 0
Views: 304
Reputation: 2820
This happens because Apple assumes that we won't present more than 1 view controller and dims the background and ALL bar button items (not sure why) as default behavior to put focus on the frontmost view.
To fix this, you just need to force the tintAdjustmentMode to Normal on the app's window in DidFinishLaunchingWithOptions.
self.window.tintAdjustmentMode = UIViewTintAdjustmentModeNormal;
Upvotes: 0
Reputation: 787
You can make a property of UINavigationController in your AppDelegate.h class.
@property (strong, nonatomic) UINavigationController *navigationController;
In your AppDelegate.m class write the code below in didFinishLaunchingWithOptions method
self.navigationController=[[UINavigationController alloc]initWithRootViewController:self.UIModalPresentationSheet];
self.window.rootViewController = self.navigationController;
Now write this code in the ViewDidLoad method of your UIModalPresentationSheet class
-(void)viewDidLoad
{
[super viewDidLoad];
self.navigationController.navigationBar.tintColor = [UIColor redColor];
}
Hope it will work.
Upvotes: 1
Reputation: 21
I've encountered this exact same anomaly in my application and have tried all of the things you've tried. I've put the code to make the color blue (in my case) in viewWillAppear and viewDidAppear and nothing seems to fix it. My guess is it's an IOS bug.
Upvotes: 0
Reputation: 640
You could try to set the color for the entire application with the appearance
property.
Set it in AppDelegate and the UI will look on all views same.
To set the tintColor
to red use:
[[UINavigationBar appearance]setTintColor:[UIColor redColor];
and
[[UIBarButtonItem appearance]setTintColor:[UIColor redColor];
You can also check out following code for even more customization:
[[UIBarButtonItem appearanceWhenContainedIn:[UINavigationBar class], nil]setTintColor:[UIColor redColor]];
Upvotes: 1
Reputation: 25459
Can you try set tint colour on your view Controller and on your navigation bar where it shows green:
viewController.view.tintColor = [UIColor redColor];
viewController.navigationController.navigationBar.tintColor = [UIColor redColor];
Upvotes: 0