Mr Riksson
Mr Riksson

Reputation: 560

Set Statusbar color to same as Nav Bar

I want the Status Bar of my app to have the exact same color as my Navigation Bar. The way I found to change the color of the Status Bar was just by creating a view in the size of the Status Bar and change the background color.

However even though I use the color picker from the Nav bar to set the color of the view I get 2 totally different colors as seen in the picture below. enter image description here

I've tried mixing with the color picker, changing opacity etc, however I'm never able to hit the correct color. Any ideas on how I can get the exact same color for the status bar?

Upvotes: 2

Views: 7571

Answers (2)

JTea
JTea

Reputation: 234

You can do the following:

  1. Create an UIImage containing only the color you want with a size of 64x1. You could render that image in code.
  2. Set the image as a background image for the navigationBar. Something like: navigationController.navigationBar.setBackgroundImage(image, for: .default)

Upvotes: 0

socaljoker
socaljoker

Reputation: 314

The color of the UIStatusBar is automatically set to match the color of the UINavigationBar when you set the value of self.navigationController.navigationBar.barTintColor. Is there a reason you need to set them separately?

Upvotes: 1

Related Questions