Assuming you are developing for iOS7+: The statusbar doesn' have any background color on its own. In fact, the reason you are seeing a dark background when the navigation bar is visible, is because it extends upwards underneath the statusbar. So if you want to keep the status bar background you can simply add a view with an appropriate background color to the current scene (viewController, window , etc.). Give it a frame of UIApplication.sharedApplication.statusBarFrame
.
-- UPDATE 1 --
Sample code (Swift 3) Gives you a solid black status bar background:
class ViewController: UIViewController {
private let statusBarUnderlay = UIView()
override func viewDidLoad() {
super.viewDidLoad()
statusBarUnderlay.backgroundColor = UIColor.black
view.addSubview(statusBarUnderlay)
}
override func viewWillLayoutSubviews() {
super.viewWillLayoutSubviews()
statusBarUnderlay.frame = UIApplication.shared.statusBarFrame
}
}
-- UPDATE 2 --
While we're at it. The above code is not how you should lay out your views. Instead, subclass UIView
and do your layout there. Then override loadView
of your UIViewController
subclass and return an instance of your custom view.
class View: UIView {
private let statusBarUnderlay = UIView()
override init(frame: CGRect) {
super.init(frame: frame)
statusBarUnderlay.backgroundColor = UIColor.black
addSubview(statusBarUnderlay)
}
required init?(coder aDecoder: NSCoder) {
fatalError("Storyboards are incompatible with truth and beauty.")
}
override func layoutSubviews() {
super.layoutSubviews()
statusBarUnderlay.frame = UIApplication.shared.statusBarFrame
}
}