Hiding status bar not working Swift 3, Xcode 8.0 - ios

Set Target/General/Deployment info to Hide status bar.
Set None for Status Bar in VCs in storyboards.
Added the following code to all VCs.
override var prefersStatusBarHidden: Bool {
return true
}
Briefly hides status bar but immediately reappears.

Only the prefersStatusBarHidden of the root-level view controller matters — here, the split view controller. The split view controller wants a status bar; it gets a status bar. That is all that matters.
You could try subclassing UISplitViewController, setting prefersStatusBarHidden in your subclass, and using that subclass in the app.

Related

Style status bar when navigation bar is hidden

I know that with UIKit usually you just override:
override var preferredStatusBarStyle: UIStatusBarStyle { return .lightContent }
in your UIViewController (or UINavigationController if it exists). It works perfectly fine.
However, I run into a problem when I perform this:
navigationController?.setNavigationBarHidden(true, animated: true)
Now, I can see no navigation bar, which is expected and perfectly fine. However, I see the status bar with the dark font, what is unexpected (my navigation controller overrides above property and it works properly when the navigation bar is not hidden). I want to see the status bar, but I want it in a light font. Navigation controller from this point does not listen to preferredStatusBarStyle, so I can't set it up this way.
Is there any way to display .lightContent status bar style when the navigation bar is hidden..?
The end effect is visible on the screenshot. If you zoom in, you can see dark letters & battery on dark background.
PS. Please do not post answers only about SwiftUI (here we support old iOS as well) & deprecated stuff.
Found a solution to make SDK ask for style when there is a navigation controller and the navigation bar is hidden but the status bar is shown.
In UINavigationController subclass, you need to override
override var childForStatusBarStyle: UIViewController? { return viewControllers.last }
And then inside these controllers, you can specify
override var preferredStatusBarStyle: UIStatusBarStyle { return .lightContent }
For some reason, if the navigation bar is hidden, iOS SDK does not ask navigation controller for preferredStatusBarStyle. However, it still asks childForStatusBarStyle and we've got an issue fixed :)
Try to set your status bar style to light
After that set View controller-based status bar appearance to NO in your info.plist
UPDATE
If you want the light content only in one view you can try to override the user interface style to dark in viewDidLoad
if #available(iOS 13.0, *) {
self.overrideUserInterfaceStyle = .dark
}

Swift 3 - how to hide Status Bar when using Over Full Screen

I'm developing a swift app and I can't find how to hide Status Bar when I use Over Full Screen presentation on my modal.
However, I put this line of code in my Modal View Controller :
override var prefersStatusBarHidden: Bool {
return true
}
And it is working if I create a segue which is not a modal, or if I create a segue which is a modal but not with Over Full Screen presentation.
I searched on internet how to fix it, and I found people who had the same problem but there had no solution.
Also, I can't change the color of my Status Bar when I'm using Over Full Screen option. I don't understand why? I think it's related.
Thanks for your help!
To hide the status bar when doing an over full screen modal, you need to set this in viewDidLoad:
override func viewDidLoad() {
super.viewDidLoad()
modalPresentationCapturesStatusBarAppearance = true
}
Then do the standard method to hide the status bar:
override var prefersStatusBarHidden: Bool {
return true
}
We can override preferredStatusBarStyle from individual view controller as you have done correctly.
Along with this, insert a new key named “View controller-based status bar appearance” and set the value to NO in your info.plist.
By disabling the “View controller-based status bar appearance”, you can set the status bar style by using the following code.
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent]; //objective-c
Hence it should solve "I can't change the color of my Status Bar when I'm using Over Full Screen option"

Hidden status bar when presenting view controller. I'm using a navigation controller for the UITableView

I have a UITableViewController with a status bar which is not hidden and I don't want it to be hidden.
When I select a UITableViewCell to go to the next detail page view controller, the status bar is still showing even though I declared for it not to be shown. Here is how I declared the status bar to be hidden in the detail view controller. But it's only hidden when it's the initial view controller, but when presented it's still shown. How can I fix it? I have added this key to my info.plist but still it didn't work.
override var prefersStatusBarHidden: Bool {
return true
}
Try to add a new entry View controller-based status bar appearance with value as NO to info.plist.

View shifts down when presenting view controller with status bar on iOS 9

I have a view controller (view1) that prefers a hidden status bar. I have a button that presents another view controller (view2) modally from the bottom of the screen (a 'Show' segue in my storyboard) and view2 prefers a visible status bar. On iOS 8, this is a smooth transition from view1 to view2, but on iOS 9 the status bar immediately appears in view1 when I press the button and the entire view of view1 shifts down to accommodate it.
This is an ugly effect and I wish to avoid it. For some reason iOS 8 handles this much more gracefully than iOS 9. Is there a fix for this?
In Swift, you can set a global variable on view2 as
isStatusBarHidden = false
on viewWillAppear of view2 change it to true and update status bar
isStatusBarHidden = true
setNeedsStatusBarAppearanceUpdate()
the status bar delegate function will look like
func prefersStatusBarHidden() {
return isStatusBarHidden
}
this only works in Swift, not Objective-C.

Preferred status bar style on iPad multitasking - split screen

I have two view controllers - the first has a UIStatusBarStyleDefault, the second has a UIStatusBarStyleLightContent.
VC1 is presenting VC2 as a modal form sheet. So when presenting in regular trait collection, VC2 is presented as UIModalPresentationFormSheet and VC1 sets the status bar to Default.
But in compact trait collection, VC2 is fullscreen and sets the status bar style to Light Content.
The problem is when switching between regular to compact (full screen to form sheet) the status bar is not updating.
Trying -
[self setNeedsStatusBarAppearanceUpdate];
after trait collection change did not solve the issue.
Any help will be much appreciated!
// This controls whether this view controller takes over control of the status bar's appearance when presented non-full screen on another view controller. Defaults to NO.
#available(iOS 7.0, *)
public var modalPresentationCapturesStatusBarAppearance: Bool
Usage:
navigationController.modalPresentationStyle = .FormSheet
navigationController.modalPresentationCapturesStatusBarAppearance = true
Once that's set the root view controller of that navigation controller can override the preferredStatusBarStyle()

Resources