My app uses a dark navigation bar color. Therefore I set the status bar color to white (so it has a nice contrast).
I did this by setting the barStyle to black (to make the status bar white) and also setting the barTint to my dark red color. Works perfectly.
I present a SafariViewController
like this:
func openWebsite(urlString: String) {
if let url = NSURL(string: urlString) {
let svc = SFSafariViewController(URL: url)
svc.delegate = self
self.presentViewController(svc, animated: true, completion: nil)
}
}
However the status bar of the presented SafariViewController
still is white. This is a problem because the SVC
navigation bar has the default white transparent iOS default style. So the status bar is basically invisible.
How can I fix that?
One of the issues that can occur is coloring the nav bar when your keyboard is open for typing. To fix this, head into General Settings –> Color of Navigation Bar when Keyboard is opened. Set this color to black as well. This should fix any issues you may have when the keyboard is open.
You can change the status bar's color and material by inserting a small view right behind it. Normally, all views are positioned below the status bar, but you can use edgesIgnoringSafeArea(. top) to push it past the safe area insets.
The style of the status bar can be changed to a status bar with white content. Go to the ViewController.swift file and add the following lines of code. override var preferredStatusBarStyle: UIStatusBarStyle { return.lightContent } The preferredStatusBarStyle property is set to lightContent.
Build and Run the project, The content of the status bar is dark again, which is the default. The reason for this is, iOS asked for the style of the status bar of the navigation controller instead of the contained view controller.
Select the View and in the Attributes Inspector change the Background Color to Light Gray. Build and Run the Project. The default style of the status bar is dark content. The style of the status bar can be changed to a status bar with white content.
The default style of the status bar is dark content. The style of the status bar can be changed to a status bar with white content. Go to the ViewController.swift file and add the following lines of code. override var preferredStatusBarStyle: UIStatusBarStyle { return.lightContent }
You can achieve that by wrapping SFSafariViewController with subclassed UINavigationController.
BlackStatusBarNavigationController.h
@interface BlackStatusBarNavigationController : UINavigationController
@end
BlackStatusBarNavigationController.h
@interface BlackStatusBarNavigationController ()
@end
@implementation BlackStatusBarNavigationController
- (UIStatusBarStyle)preferredStatusBarStyle {
return UIStatusBarStyleDefault;
}
@end
Use like this:
UINavigationController *navigationController = [[BlackStatusBarNavigationController alloc] initWithRootViewController:viewController];
navigationController.navigationBarHidden = YES;
[self presentViewController:navigationController animated:YES completion:nil];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With