My current application runs on iOS 5 and 6.
The navigation bar is having an orange color and the status bar is having a black background color with white text color. However, when I run the same application on iOS 7, I observe the status bar looks transparent with the same orange background color as the navigation bar and the status bar text color is black.
Due to this I'm not able to differentiate between the status bar and the navigation bar.
How do I make the status bar to look the same as it was in iOS 5 and 6, that is with black background color and white text color? How can I do this programmatically?
Warning: It does not work anymore with iOS 13 and Xcode 11.
========================================================================
I had to try look for other ways. Which does not involve addSubview
on window. Because I am moving up the window when keyboard is presented.
- (void)setStatusBarBackgroundColor:(UIColor *)color {
UIView *statusBar = [[[UIApplication sharedApplication] valueForKey:@"statusBarWindow"] valueForKey:@"statusBar"];
if ([statusBar respondsToSelector:@selector(setBackgroundColor:)]) {
statusBar.backgroundColor = color;
}
}
func setStatusBarBackgroundColor(color: UIColor) {
guard let statusBar = UIApplication.sharedApplication().valueForKey("statusBarWindow")?.valueForKey("statusBar") as? UIView else {
return
}
statusBar.backgroundColor = color
}
func setStatusBarBackgroundColor(color: UIColor) {
guard let statusBar = UIApplication.shared.value(forKeyPath: "statusBarWindow.statusBar") as? UIView else { return }
statusBar.backgroundColor = color
}
Calling this form application:didFinishLaunchingWithOptions
worked for me.
N.B. We have an app in the app store with this logic. So I guess it is okay with the app store policy.
Edit:
Use at your own risk. Form the commenter @Sebyddd
I had one app rejected cause of this, while another was accepted just fine. They do consider it private API usage, so you are subject to luck during the reviewing process :) – Sebyddd