How to Hide the Status Bar in a Swift iOS App

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
}

Hide Status Bar in iOS 13

Step 1 :- add permission

Sample Image

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 ...:)

Hide status bar on iOS Swift

What you can do is to show and hide in Appear and Disappear

   override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
navigationController?.isNavigationBarHidden = true
}

override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
navigationController?.isNavigationBarHidden = false
}

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 status bar swift 4

You probably found your own solution to this already, but I got it working this way:

override func viewWillAppear(_ animated: Bool) {
// Sets the status bar to hidden when the view has finished appearing
let statusBar: UIView = UIApplication.shared.value(forKey: "statusBar") as! UIView
statusBar.isHidden = true
}

override func viewWillDisappear(_ animated: Bool) {
// Sets the status bar to visible when the view is about to disappear
let statusBar: UIView = UIApplication.shared.value(forKey: "statusBar") as! UIView
statusBar.isHidden = false
}

Cannot hide status bar in a specific view controller in iOS 11, Swift 4

In view controller where you want to hide the status bar,

In the viewWillAppear method, UIApplication.shared.isStatusBarHidden = true,

In the viewWillDisAppear method, UIApplication.shared.isStatusBarHidden = false

Hide statusbar during splash screen

This is updated for Swift 3 of Xcode 8.3.3

In your Info.plist add the following key:

info.plist

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:

buildOptions

Hope that helps!

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 status bar in all view controllers - IOS

Go to your Info.plist file and add a new attribute:

View Controller based status bar appearance and set it to NO.

Sample Image

Then go to App Delegate and replace your method to this:

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.

UIApplication.shared.isStatusBarHidden = true
return true
}


Related Topics



Leave a reply



Submit