Search code examples
xcodecolorsios9statusbar

How to refresh preferredStatusBarStyle in one ViewController for two or more times


My old code :

- (void)setStatusBarLight:(BOOL)value {
    if (value) {
        [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
    } else {
        [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault];
    }
}

Now setStatusBarStyle is deprecated. Apple says, that i should use preferredStatusBarStyle. But this calls only once. But in my option status bar must change color after some user actions in this view controller.

What can I do ?


Solution

  • Here is a solution:

    [self setNeedsStatusBarAppearanceUpdate];
    

    And View controller-based status bar appearance set to YES in Info.plist