Hide Status Bar In iOS 8 app
Solution 1:
You need to override this method on each view controller unless you have that plist entry.
Objective-C
-(BOOL)prefersStatusBarHidden{
return YES;
}
Swift 2
override func prefersStatusBarHidden() -> Bool {
return true
}
Swift 3+
override var prefersStatusBarHidden: Bool {
return true
}
And don't forget to set (if you present a view controller by calling the presentViewController:animated:completion: method):
Objective-C
vcToBeShownWithoutStatusbar.modalPresentationCapturesStatusBarAppearance = YES;
Swift
vcToBeShownWithoutStatusbar.modalPresentationCapturesStatusBarAppearance = true
Documentation: https://developer.apple.com/reference/uikit/uiviewcontroller/1621453-modalpresentationcapturesstatusb
If you change status bar from some container view controller (eg. UINavigationController
or UIViewController
with child view controllers) and you would like to change view controller responsible for status bar you should use childViewControllerForStatusBarHidden:
property. Eg:
Set first view controller instance always responsible for status bar management
Objective-C
- (UIViewController *)childViewControllerForStatusBarHidden {
return childViewControllers.first; // or viewControllers.first
}
Swift 2
override var childViewControllerForStatusBarHidden() -> UIViewController? {
return childViewControllers.first // or viewControllers.first
}
Swift 3+
override var childViewControllerForStatusBarHidden: UIViewController? {
return childViewControllers.first // or viewControllers.first
}
Set container view controller responsible for status bar management
Objective-C
- (UIViewController *)childViewControllerForStatusBarHidden {
return nil;
}
Swift 2
override func childViewControllerForStatusBarHidden() -> UIViewController? {
return nil
}
Swift 3+
override var childViewControllerForStatusBarHidden: UIViewController? {
return nil
}
Documentation: https://developer.apple.com/documentation/uikit/uiviewcontroller/1621451-childviewcontrollerforstatusbarh
Solution 2:
- Go to Info.plist file
- Hover on one of those lines and a (+) and (-) button will show up.
- Click the plus button to add new key
- Type in start with capital V and automatically the first choice will be View controller-based status bar appearance. Add that as the KEY.
- Set the VALUE to "NO"
- Go to you AppDelegate.m for Objective-C (for swift language: AppDelegate.swift)
- Add the code, inside the method
For Objective-C:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[application setStatusBarHidden:YES];
return YES;
}
For Swift:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey:Any]?) -> Bool {
application.statusBarHidden = true
return true
}
Done! Run your app and no more status bar!