Search code examples
cocoa-touchios8uinavigationbarstatusbar

Status Bar turning completely black when using clipsToBounds = YES in iOS8. How do I change this?


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]


Solution

  • 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.