user1416564 user1416564 - 4 months ago 24
iOS Question

iOS 8 make statusbar black and not translucent

So my status bar in my app currently looks like this:

1

And I'd rather it look something like this:

2

So that it's black with white text. At the moment it doesn't work on this particular screen because the background isn't black. And I've already set the

Status Bar Style
in the pList to
UIStatusBarStyleLightContent
.

I'll also add that the View is the initial ViewController AND it doesn't have a
UINavigationController
embedded into it:

EDIT: This is not a duplicate because most of the other previous solutions are outdated already.

Answer

You can just set it to light and then toss a view behind it. You'll also have to account for device rotation if you allow that in your app.
Swift:

override func viewDidLoad() {
    super.viewDidLoad()

    let statusBG = UIView(frame: CGRect(x: 0, y: 0, width: UIScreen.mainScreen().bounds.width, height: 21))
    statusBG.backgroundColor = UIColor.blackColor()
    view.addSubview(statusBG)
}

Objective-C:

- (void)viewDidLoad {
    [super viewDidLoad];
    UIView *statusBG = [[UIView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 21)];
    statusBG.backgroundColor = [UIColor blackColor];
    [self.view addSubview:statusBG];
}