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)
}
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
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)
you can do like
override var prefersStatusBarHidden: Bool {
return true
}
for more option you can go Status Bar Hidden
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.