I am trying to hide status bar in one of my UIViewControllers (Swift 4).
Firstly, I set View controller-based status bar appearance to
None of these worked for me either working on a converted project in iOS 11. Here's what I did. I added this code in the AppDelegate
func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey : Any]? = nil) -> Bool
{
application.isIdleTimerDisabled = true
application.isStatusBarHidden = true
return true
}
Just change "Top Space to" constraint of your view from Safe area to Superview. And it will drag your view under the Status bar so there is will be no need to hide it]1
As you said, you are using UINavigationController to navigate to your custom view controller. I suppose you have set your Custom View controller as the root view of your UINavigationController. In this case overriding var prefersStatusBarHidden in your custom view controller won't work but you will have to subclass your UINavigation Controller and override the property there as shown below:-
class CustomNavigationController: UINavigationController {
override var prefersStatusBarHidden: Bool {
return true
}
}