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.
- (void)viewDidLoad
{
[super viewDidLoad];
if ([self respondsToSelector:@selector(setNeedsStatusBarAppearanceUpdate)])
{
[self prefersStatusBarHidden];
[self performSelector:@selector(setNeedsStatusBarAppearanceUpdate)];
}
else
{
// iOS 6
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationSlide];
}
}
// Add this method
- (BOOL)prefersStatusBarHidden {
return YES;
}
To hide for a specific ViewController (and then turn back on) when View controller-based status bar appearance
set to NO
:
-(void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationFade];
}
-(void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
[[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationFade];
}
on swift 4:
UIApplication.shared.isStatusBarHidden = ..true/false
in iOS7 you should implement in your viewController
- (BOOL)prefersStatusBarHidden {
return YES;
}
If anyone wanted the most updated way to do it (Swift 2.1 and latest Xcode 7.2)
Set "View controller based status bar appearance to NO in your info.plist"
UIApplication.sharedApplication().statusBarHidden = true // put inside app delegate somewhere (applicationWill or DidFinishLaunchingWithOptions:
you can hide status bar to set the key value "View controller-based status bar appearance" NO in plist. This is easiest way.
or You can hide in code by using property statusBarHidden of UIApplication class.
[[UIApplication sharedApplication] setStatusBarHidden:YES];
Swift 3.0
Hide status bar for any particular view controller
override var prefersStatusBarHidden: Bool {
get {
return true
}
}
Hide Status bas across the application
UIApplication.shared.isStatusBarHidden = true
and set the key value "View controller-based status bar appearance" NO in info plist of project.