random random - 3 months ago 23
iOS Question

UINavigationBar and UITabBar tint to match UIView

I am setting the

barTintColor
of
UINavigationBar
and
UITabBar
. I want my
UIView
's background to be the exact same color so that the nav bar and tab bar appear invisible. However, I can't get the colors to match.

Here is the background set to the exact same color as the navigation bar.
enter image description here

Here is how I'm adjusting the color of the bars:

[[UINavigationBar appearance] setBarTintColor:[UIColor colorWithRed:0.78 green:0.05 blue:0.2 alpha:1]];
[[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];
[[UINavigationBar appearance] setTranslucent:NO];

Answer

I replicated your steps almost exactly and was able to match the colors.

enter image description here

The main difference was I set the barTintColor: directly to it's root view's background color.

Here is my code:

 itemsViewController.view.backgroundColor = [UIColor redColor];

UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:itemsViewController];


navController.navigationBar.barTintColor = itemsViewController.view.backgroundColor;
navController.navigationBar.tintColor = [UIColor whiteColor];
navController.navigationBar.translucent = NO;

So I'm going to say that your issue is that you are not setting the right barTintColor: because your RGB color values are incorrect. I'd focus your efforts there.

Comments