Search code examples
iosobjective-cuistatusbar

iOS StatusBarStyle not changing when set to light


I'm developing an app where i want the navigationBar to be invisible and have a dark background. I want the status bar colour to be white. I also want the status bar to be hidden initially.

I have set the Status Bar Style to Light

https://i.sstatic.net/d4GoW.png

But the result i get is always black colour text status bar as shown below.

https://i.sstatic.net/6qgAu.png

I have tried to set the "View controller-based status bar appearance" to NO and the result was to have a hidden status bar. I also tried to have prefersStatusBarHidden returning NO but still the same.

I have tried to "View controller-based status bar appearance" to YES and the result was black text. I tried to have preferredStatusBarStyle returning UIStatusBarStyleLightContent but still the same.

I'm i doing something wrong. Thanks in advance.


Solution

  • The problem was cause to the UINavigationController the initial view controller was embedded in. I have subclassed UINavigationController (NLNavigationController) and set the custom class of the initial navigation controller to this (NLNavigationController). In the new subclass i had this.

    - (void)viewDidLoad {
        [super viewDidLoad];
        [self setNeedsStatusBarAppearanceUpdate];
    }
    
    -(BOOL)prefersStatusBarHidden{
        return NO;
    }
    
    -(UIStatusBarStyle)preferredStatusBarStyle{
        return UIStatusBarStyleLightContent;
    }
    

    For all this to work i had to set in the info.plist

    View controller-based status bar appearance set to YES

    With this changes i got the following result.

    https://i.sstatic.net/x88Ae.png