For a non-fullscreen presentation of a View Controller, you need to use the modalPresentationCapturesStatusBarAppearance
property.
e.g.
toViewController.modalTransitionStyle = .coverVertical
toViewController.modalPresentationStyle = .overFullScreen
toViewController.modalPresentationCapturesStatusBarAppearance = true
fromViewController.present(toViewController,
animated: true,
completion: nil)
For a fullscreen presentation of a View Controller, you need to:
- set the new VC's
modalPresentationStyle
.
- override
prefersStatusBarHidden
in the new VC
- set your app plist
UIViewControllerBasedStatusBarAppearance
value to YES
e.g.
toViewController.modalTransitionStyle = .coverVertical
toViewController.modalPresentationStyle = .fullScreen
fromViewController.present(toViewController,
animated: true,
completion: nil)
(Yes, status bar setting in iOS is pitifully bad. It's no wonder Stack Overflow has so many questions on the subject, and so many varied answers.)