1

I'm presenting a navigation controller with a view controller embedded in it and i want the status bar to be hidden. The good news is the status bar is hidden on simulator. But its not hidden when I test it on the actual iPhone. Here is my code.

let storyboard = UIStoryboard(name: "Login:SIgnUp", bundle: nil)
                if let vc = storyboard.instantiateViewController(withIdentifier: "Welcome") as? WelcomeVC {
                    vc.modalPresentationCapturesStatusBarAppearance = true
                    vc.modalPresentationStyle = .custom
                    vc.modalTransitionStyle = .crossDissolve
                    self.present(vc, animated: true, completion: nil)
                }
john
  • 507
  • 1
  • 5
  • 15

3 Answers3

1

Write this method on each view controller unless you have that plist entry.

Objective-c

-(BOOL)prefersStatusBarHidden{
    return YES;
}

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
Vikash Kumar
  • 642
  • 1
  • 11
  • 25
0

You can write this code in viewWillAppear:

UIApplication.shared.setStatusBarHidden(true, with: .slide)

And if you don’t want to hide status bar for other views then you should hide in viewWillDisappear:

UIApplication.shared.setStatusBarHidden(false, with: .slide)
Patrick R
  • 6,621
  • 1
  • 24
  • 27
0

you can do like

override var prefersStatusBarHidden: Bool {
    return true
}

for more option you can go Status Bar Hidden

Community
  • 1
  • 1
Foolish
  • 159
  • 10