简体   繁体   中英

Dark statusbar in TabBar controller?

I'm having this odd issue, where my status bar gets all black, only when I'm using a tab bar controller. Is there a way to fix this? I obviously want it the same color as the navigation bar.

在此输入图像描述

Here's a screenshot of the navigation and tab bar controller in my storyboard.

在此输入图像描述

  1. You can change the info.plist the row View controller-based status bar appearance and set it to NO
  2. Then put this line of code in your appDelegate.swift in didFinishLaunchingWithOptions

    UIApplication.shared.statusBarStyle = .lightContent

This problem seems to be the navigation bar not covering the background of the status bar. You should embed your view controller in navigation controller instead of adding navigation bar directly.

By the looks of what i'm seeing your status bar seems fine since its white on a dark color

What you need to do is change your Bar Tint Color in the Navigation Controller as follows

在此输入图像描述

The on change it on the attribute inspector

在此输入图像描述

Hope this helps

Try adding View controller-based status bar appearance to info.plist and set the value to NO. And add this in app delegate:

UIApplication.shared.statusBarStyle = .lightContent

Or

Try overriding this method:

override var preferredStatusBarStyle: UIStatusBarStyle {
    return .lightContent
}

UINavigationBar has a bit of a strange behavior when it comes to the color you set on it. As other members have pointed out, you do have to set the translucent boolean to false, but this isn't all to get your bar to match the color you are trying to set. It will be close, but if you look carefully it will not be the exact color you are trying to use. In order to set the true color on UINavigationBar you need to understand what it is doing.

Let's say that I wanted to set my UINavigationBar to this cool color green.

That would be an RGB value of: R=90 | G=200 | B=95.

What UINavigationBar will do is apply it's built-in styling by giving this green a "glossy" look. The result for us is that it is taking our green RGB values and upping each by a factor of 20.

If you look close the green square above does not exactly match the one UINavigationBar is displaying with the same RGB values. This looks just slightly brighter.

To fix this, simply reduce the RBG values by 20 for the color you intend to use for the UINavigationBar's in your application.

So R=90 | G=200 | B=95 will become R=70 | G=180 | B=75.

I think in you case you should try to change statusView background color.

The better place is setupAppearances func which called at the start of app.

let yourColor: UIColor = .gray
UIApplication.shared.statusBarView?.backgroundColor = yourColor

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM