Hide Status Bar In iOS 8 app
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
How to hide a status bar in iOS?
Add the following code to your view controller:
if ([self respondsToSelector:@selector(setNeedsStatusBarAppearanceUpdate)]) {
// iOS 7
[self performSelector:@selector(setNeedsStatusBarAppearanceUpdate)];
} else {
// iOS 6
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationSlide];
}
- (BOOL)prefersStatusBarHidden {
return YES;
}
Hide the status bar in ios 9
Swift-3
override var prefersStatusBarHidden: Bool {
return true
}
I got the Information From Here
Change
func
tovar
Delete
()
Change
->
to:
This works because a computed variable has a getter function, so the function you were implementing before simply turns into the getter function
2016 onwards: simple Thing like
On your info.plist add the following two property for statusBar Hidden
View controller-based status bar appearance (Boolean: NO)
Status bar is initially hidden (Boolean: YES)
By Source
UIStatusBarHidden
UIViewControllerBasedStatusBarAppearance
or
Old answers ! ...
add
application.statusBarHidden
indidFinishLaunchingWithOptions
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
application.statusBarHidden = YES;
return YES;
}
and add
in
info.plist
add thisView controller-based status bar appearance
setNO
View controller-based status bar appearance = NO
viewcontroller based hidden set
Add method in your view controller.
Objective -C
- (BOOL)prefersStatusBarHidden {
return YES;
}
Swift upto 2
override func prefersStatusBarHidden() -> Bool {
return true
}
(GOOD) 2016.5.17 in iOS 9.0 worked nicely.
Updated Answer
- 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: [NSObject:AnyObject]?) -> Bool {
application.statusBarHidden = true
return true
}
Hide Status Bar in iOS 13
Step 1 :- add permission
Step 2 :- add the below code in desired view controller to hide the status bar .
override var prefersStatusBarHidden: Bool {
return true
}
NOTE :- if you don't set constrain properly after the hidden true / false you will have design issues , so take care about it ...:)
How do I hide the status bar in a Swift iOS app?
You really should implement prefersStatusBarHidden on your view controller(s):
Swift 3 and later
override var prefersStatusBarHidden: Bool {
return true
}
How to programmatically hide and show status bar in iOS 13?
If you want to show/hide the status bar on the different View Controllers you need to:
- Add View controller-base status bar appearance option in your Info.plist and set it to YES
- Override
var prefersStatusBarHidden: Bool
in each View Controller where you want to have the status bar shown/hidden
override var prefersStatusBarHidden: Bool {
return true
}
If you want to show/hide it dynamically (ex. after tapping on button), you could do something like this:
var statusBarHidden = true {
didSet {
setNeedsStatusBarAppearanceUpdate()
}
}
override var prefersStatusBarHidden: Bool {
return statusBarHidden
}
You could find more verbose explanation here Here
Also in the Apple Documentation for
UIStatusBarManager
you can find the following quote:
You do not use this object to modify the configuration of the status bar. Instead, you set the status bar configuration individually for each of your UIViewController objects. For example, to modify the default visibility of the status bar, override the prefersStatusBarHidden property of your view controller.
How to hide the app status bar
Turns out I was previously compensating for the status bar being there with:
webView.scrollView.contentInset = UIEdgeInsets(top: 20, left: 0, bottom: 0, right: 0)
changed the top value to 0
and along with the 5 steps in the question and that has worked.
Hide statusbar during splash screen
This is updated for Swift 3 of Xcode 8.3.3
In your Info.plist add the following key:
Then in your AppDelegate file add the following in didFinishLaunchingWithOptions
section:
func application(_application:UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
UIApplication.shared.isStatusBarHidden = false
return true
}
That should sort out your problem.
You can also configure the launch colour in your project Build Settings if this is a problem for you:
Hope that helps!
Related Topics
Iterate Over Snapshot Children in Firebase
I Have Real Misunderstanding With Mfmailcomposeviewcontroller in Swift (Ios8) in Simulator
Getting List of Files in Documents Folder
How to Detect Collision in Swift, Sprite Kit
Using Custom Fonts in Wkwebview
Uipageviewcontroller and Storyboard
How to Save an Array of Objects to Nsuserdefault with Swift
How to Present Popover Properly in iOS 8
How to Get the Name of Image Picked Through Photo Library in Iphone
Ios9 Getting Error "An Ssl Error Has Occurred and a Secure Connection to the Server Cannot Be Made"
How to Allow Didset to Be Called During Initialization in Swift