4
votes

I need to change status bar style depending on the view controller so in my plist-file "View controller-based status bar appearance" is set to YES.

And I need to sometimes hide the status bar!

I'm trying to use setStatusBarHidden but it seems to work only if "View controller-based status bar appearance" is set to NO ...

So is there a way to hide the status bar ?

1
Override the prefersStatusBarHidden method in your view controllerdan
Setting the prefersStatusBarHidden would only work if View controller-based status bar appearance is set to YESfaris.halteh

1 Answers

1
votes

First, declare a variable to indicate hidden or not:

@interface ExampleViewController
{
    BOOL statusBarHidden;
}

Second, override UIViewController's method which depends the variable:

- (BOOL)prefersStatusBarHidden {
    return statusBarHidden;
}

Finally, when you need to hide status bar, do:

statusBarHidden = YES;
[self setNeedsStatusBarAppearanceUpdate];

When you need to display status bar again, do:

statusBarHidden = NO;
[self setNeedsStatusBarAppearanceUpdate];