Domanda

I have a basic master-detail app. Depending on the item that is selected in the master list, I'd like to set the tintColor of the navigation bar in the details view only.

I set the tint color like so: self.navigationController.navigationBar.tintColor = detailTintColor; in viewWillAppear: of the details controller.

However, this also changes the color of the master controller's navigation bar to yellow (should remain red), which is visible as a flickering during the transition animation. I assume because there is only one navigation bar instance.

Here a screenshot to illustrate the problem:

  • The "i" icon is in the master view controller's navbar and should be red, not yellow

enter image description here

È stato utile?

Soluzione

In iOS 8 we set tint color by this :-

self.navigationController.navigationBar.barTintColor = [UIColor redColor];

Altri suggerimenti

why not resetting to original color when view disapperars?

-(void)viewWillDisappear:(BOOL)animated {
    self.navigationController.navigationBar.tintColor = yourSavedColor;
    [super viewWillDisappear:animated];
}

You only have to change the tint color of the UINavigationBar in the Details UINavigationController in Storyboard:

enter image description here

Working sample:

enter image description here

You could use the UIAppearance API to obtain the same result by subclassing UINavigationController, and setting the details controller to be that custom class. Then, using UIAppearance API, set the UINavigationBar tint color:

[[UINavigationBar appearanceWhenContainedIn:[DetailNavigationController class], nil] setTintColor:[UIColor redColor]];
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top