2

I'm setting my NavigationBar's translucent property to NO via the UINavigationBar appearance proxy in my AppDelegate.

Then, to get rid of the 1 pixel-height separator between UINavigationBar and my view's below it, in my ViewController, I'm setting self.navigationcontroller.navigationbar.clipsToBounds = YES;.

This is to remove the separator and achieve an effect similar to this...

enter image description here

There's an additional view with Dates underneath the UINavigationBar.

However, when I begin to use clipsToBounds = YES, my status bar goes completely black. I don't want this. I want it to be 'blue', just like it is in the photo for this CBS Sports app.

How can I change the color of the status bar, or why is my color from the navigation bar no longer extending up to the status bar? [Also, I'm using an embedded NavigationController, not one that I dragged out onto the view]

chris P
  • 6,359
  • 11
  • 40
  • 84

2 Answers2

5

Do not set the clipsToBounds property to YES. The way extended bars work is the layer is drawn beyond its bounds until under the status bar.

You have two options here. One is to remove the separator using runtime trickery, which I have explained how to do in this answer.

Since your case does not involve translucent navigation bar, it will be much simpler. What you want to set is shadowImage to be empty like so:

self.navigationController.navigationBar.shadowImage = [UIImage new];

But you'll notice this does not work right away. Documentation mentions that this will not work until a background image is not set using one of the setBackgroundImage: methods. Since your bar is not translucent and has a single color, you can create a 1x1px wide image with the color, and set it as the background image.

Léo Natan
  • 56,823
  • 9
  • 150
  • 195
  • I just realized a potential issue. So I have a 1x1px image with my apps default Nav Color. However, I allow my users to choose multiple Color Themes in the application. They can change from blue to red to orange and many other colors. I change everything, including images, using their masks. Is this solution going to prevent me from doing this if I have to have the 1x1px wide image a static color? – chris P May 12 '15 at 17:00
  • No, because you can create an image with a color. I think my other solution will be better for you. Take a look at my link. – Léo Natan May 12 '15 at 17:01
  • ok, so I just need to hide that uiimageview as hidden? Is it a sub view of the nab bar? So I just iterate the nab bars children to find it? – chris P May 12 '15 at 17:07
3

A problem here is that when you set clipsToBounds to true, you lose the top of the status bar. What I do, therefore, is just the opposite of what you're doing - I make the navigation bar absolutely transparent:

    self.navbar.backgroundColor = UIColor.clearColor()
    self.navbar.translucent = true
    self.navbar.setBackgroundImage(UIImage(), forBarMetrics:.Default)
    self.navbar.clipsToBounds = true

Now we are just seeing right through the navigation bar to whatever is behind it. So you can have whole top area of your view controller's view be blue, and you just see it.

matt
  • 515,959
  • 87
  • 875
  • 1,141