Question

On iOS7 of iPad, first, I setup an modal view controller, the size is 320 * 460, then, in this modal view controller, I presented another navigation view controller, after this, the tint color of navigation bar and tool bar of the presented navigation controller turns gray. I have tried to set tint color of navigation bar and tool bar, but it just doesn't work.

Then I tried to present the navigation controller directly, then all tint color works both on navigation bar and tool bar.

I have tried with the barTintColor property of navigation bar and tool bar, it works.

I don't know what happens.

Update

first, I define a view controller: modalViewController The present the modal view controller like this:

if (DeviceIsPad()) // DeviceIsPad is a method defined somewhere to tell that the device is an iPad.
    modaViewController.modalPresentationStyle = UIModalPresentationFormSheet;

//here self is a normal view controller
[self presentViewController:modalViewController animated:YES completion:NULL];

Second, define a navigation view controller: navigationController Present the navigation controller like this:

if (DeviceIsPad())
    navigationController.modalPresentationStyle = UIModalPresentationCurrentContext;

// here self means the modalViewController mentioned above
[self presentViewController:navigationController animated:YES completion:nil];

I setup the navigation bar and toolbar bar items in 'viewDidLoad' method of navigationController.

By default, when the navigation view controller comes out, all toolbar button items(The items are built with just basic title like Cancel, OK) turns to be gray.

At the same time, I have tried to set tintColor of tool bar and navigation bar. Both instance method and appearance method(like [[UIToolBar appearance] setTintColor:[UIColor blueColor]]) are used. But it still doesn't work.

And then I tried to present the navigationViewController mentioned above with UIModalPresentationFormSheet style directly from a normal view controller, then all tintColor for navigation bar and tool bar turns to be the blue color(the system blue color).

Was it helpful?

Solution

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;

OTHER TIPS

Try setting

 [[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"NavBarBGTile.png"] forBarPosition:UIBarPositionTopAttached barMetrics:UIBarMetricsDefault];

Where NavBarBGTile.png is a 1X1px tile image that in the color you want as navigation bar color

Also

  [[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];

Replace white with whatever you want

These lines should place at the begining of application launch

Try This Code:

UIView *masterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 300, 260)];
UIToolbar *pickerToolbar = [self createPickerToolbarWithTitle:@"Surgeons"];
pickerToolbar.barTintColor= [UIColor blueColor];
pickerToolbar.translucent=YES;
[masterView addSubview:pickerToolbar];
[masterView addSubview:pickerViewObj];
UIViewController *viewController = [[UIViewController alloc] initWithNibName:nil bundle:nil];
viewController.view = masterView;
viewController.contentSizeForViewInPopover = viewController.view.frame.size;
self.popoverController =[[UIPopoverController alloc] initWithContentViewController:viewController];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top