In ios7, how can I hide the statusbar programmatically? I am using XCode 4.6.1 (ios6.1) and I want to implement this in XCode itself.
If you need to hide/show it on a given view controller dynamically you can do something like this.
(Although I recommend just using - (BOOL)prefersStatusBarHidden to return your preference if you don't need it to change.)
// view controller header
@interface MyViewController : UIViewController {
BOOL shouldHideStatusBar;
}
@end
@implementation
- (BOOL)prefersStatusBarHidden {
return shouldHideStatusBar; // backed by your instance variable
}
- (void)setPrefersStatusBarHidden:(BOOL)hidden {
shouldHideStatusBar = hidden;
// Don't call this on iOS 6 or it will crash since the
// `setNeedsStatusBarAppearanceUpdate` method doesn't exist
[self performSelector:@selector(setNeedsStatusBarAppearanceUpdate)];
// [self setNeedsStatusBarAppearanceUpdate]; // (if Xcode 5, use this)
}
@end