0
votes

I am trying to change my statusbar style (the color of status bar text, more specifically) depending on which viewController is active through this:

self.navigationController.navigationBar.barStyle = UIBarStyleBlack;

But that does not work. Rather, it makes the whole navigationBar black (instead of just the statusbar). Neither does the following:

- (UIStatusBarStyle)preferredStatusBarStyle {
    return UIStatusBarStyleLightContent;
}

But this only seems to work when the viewController is not embedded in a navController (when I hide the navBar, it works!). My viewController hierarchy is the following:

tabBarController -> navigationControllers -> viewController

Also: Setting 'View controller-based status bar appearance' to YES & NO does not make a difference.

I am glad for any help!

1
preferredStatusBarStyle changes the color of the status bar text. UIStatusBarStyleLightContent will show white text in the status bar. What is the actual result you want? - rmaddy
That is exactly what I want to happen. Also, it should change between different viewControllers. I have read on other threads that this should not work for VCs within navigationControllers, but the alternative (by setting the navBar style) doesn't work either. - Besfort Abazi

1 Answers

0
votes

You can try following. keep this to your ViewController

-(UIStatusBarStyle)preferredStatusBarStyle{    
    // Add If/else conditions based on which style required on which condition
    return UIStatusBarStyleLightContent;
}

Call this code when you want to change the status bar style..

[self preferredStatusBarStyle];
[self setNeedsStatusBarAppearanceUpdate];