Hide StatusBar on iOS 13.5

In iOS 12 and 13, up to 13.4, few lines of codes:

navigationController?.navigationBar.isTranslucent = false

navigationController?.navigationBar.barTintColor = .black

navigationController?.navigationBar.tintColor = .red

allow to hide the status bar under the navigation bar.

With swiftUI is perhaps even simpler

.statusBar(hidden: hideStatusBar)

but it requires to rewrite the whole app from storyboard to swiftUI.

Hiding the status bar, or go to full screen, is still be possible without using swiftUI on legacy code?

Answered by Luca_65 in 421244022

I found the issue origin, which is correlated to the Dark Mode (that I had inadvertently changed)

The 2 codes' lines:

navigationController?.navigationBar.isTranslucent = false
navigationController?.navigationBar.barTintColor = .black

determine a dark background of the statusBar.

In Light Mode the StatusBar foregroundColor is black so it disappers, in Dark Mode it's white, so it emerge on the dark background.


These two settings into info.plist turn off the initial statusBar and don’t turn it on later:

UIStatusBarHidden (Status bar is initially hidden) YES
UIViewControllerBasedStatusBarAppearance (View controller-based status bar appearance) NO

(from h ttps://stackoverflow.com/questions/18979837/how-to-hide-ios-status-bar/18980833#18980833)

Thank you Claude for your patiently support.

Why this question ? Have you found problem with iOS 13.5 with those 3 lines of code ?


I would avoid rewriting in SwiftUI. You may solve one specific point and create 10 more…

With iOS 13.5 that lines of codes doesn’t hide anymore the status bar. I agree with you in preferring to modify some lines of codes than re-develop the app in SwiftUI.

OK, the 3 lines mask the status bar.


Have you checked in the VC (Attributes inspector for the VC itself) how transition and presentation are defined ? Test with fullscreen instead of automatic.

Thanks Claude,

The VC Attribute Selector "Layout / Use Full Screen (Deprecated)" has no effect.

I also tryied the VC attributes "SImulated Metrics", which infer the canvas but not the iPhone, as its title describes, and the Layout attributes, all without effect.

In the info.plist I added "UIStatusBarHidden = YES"; It immediately changes to "Status bar is initially hidden = YES" and works for the LaunchScreen only.

I'm not sure we speak of the same thing.


What I described:

- In IB, select the first VC. Select the VC itself.

In Attributres Inspector, you should see sections :

- Simulated metrics

- View Controller

Here, look at Presentation. What is it ?

Turn it to Fiull screen


I do not see it deprecated anywhere. Unless it is in iOS 13.5 (did not install yet).

Thank you Claude for the clarification.

Before I've pointed to "Use Full Screen (Deprecated)". I verified with Presentation: Full Screen and Over Full Screen. In all cases the status bar is visible on the iPhone with iOS 13.5 (last beta).

What I do not understand is that hiding status bar depends on where the nav bar is positioned.


Where is it positioned in your case ? Over status bar ? How do you position it here ?

Where do you put the 3 lines of code ?

In viewDidload ?

TRry in viewWillAppear or viewDidAppear.


Maybe (need to check with iOS 13.5) they have changed a bit the sequence to display statusBar ?

Accepted Answer

I found the issue origin, which is correlated to the Dark Mode (that I had inadvertently changed)

The 2 codes' lines:

navigationController?.navigationBar.isTranslucent = false
navigationController?.navigationBar.barTintColor = .black

determine a dark background of the statusBar.

In Light Mode the StatusBar foregroundColor is black so it disappers, in Dark Mode it's white, so it emerge on the dark background.


These two settings into info.plist turn off the initial statusBar and don’t turn it on later:

UIStatusBarHidden (Status bar is initially hidden) YES
UIViewControllerBasedStatusBarAppearance (View controller-based status bar appearance) NO

(from h ttps://stackoverflow.com/questions/18979837/how-to-hide-ios-status-bar/18980833#18980833)

Thank you Claude for your patiently support.

Thanks for feedback. Don't forget to close now.

To completeness, to programmatically control the visibility of the StatusBar, in the UIViewController class override the read-only computed property:

overridevar prefersStatusBarHidden: Bool
{
     return true
}

In Objective C it is as simple as

- (BOOL) prefersStatusBarHidden {

	return YES;
}
Hide StatusBar on iOS 13.5
 
 
Q