I am trying to change the color of the status bar to like a blue, or some other color.
Is this possible, or does Apple not allow it?
I am trying to change the color of the status bar to like a blue, or some other color.
Is this possible, or does Apple not allow it?
I made this extension to change color of status bar
Here is usage anywhere in viewcontroller:
setStatusBar(color: .red)
NOTE: This solution fails under iOS 13 and later.
First in Plist set
View controller-based status bar appearance
toNO
The output screenshot is below
But with the release of
iOS 7
, you’re allowed to change the appearance of the status bar. Hence I am posting my workaround.From an individual view controller by overriding the
preferredStatusBarStyle
:Alternatively, you can set the status bar style by using the
UIApplication statusBarStyle
method. To do this, insert a new key named “View controller-based status bar appearance” and set the value to NO.By disabling the “View controller-based status bar appearance”, you can set the status bar style by using the following code.
At the end, change the
UINavigationBar
property tint color like belowHere is my workaround: create a
UIView
, add it to your root view of view controller as artificial status bar background1.Create a
UIView
2.Add it to your view controller's root view
There your go.
3.(Additional)Change the content color on status bar, only white or black.
This workaround does not use private API, so you're safe. :-)
You can set background color for status bar during application launch or during viewDidLoad of your view controller.
Here is result:
Here is Apple Guidelines/Instruction about status bar change. Only Dark & light (while & black) are allowed in status bar.
Here is - How to change status bar style:
If you want to set status bar style, application level then set
UIViewControllerBasedStatusBarAppearance
toNO
in your `.plist' file.if you wan to set status bar style, at view controller level then follow these steps:
UIViewControllerBasedStatusBarAppearance
toYES
in the.plist
file, if you need to set status bar style at UIViewController level only.In the viewDidLoad add function -
setNeedsStatusBarAppearanceUpdate
override preferredStatusBarStyle in your view controller.
-
Set value of .plist according to status bar style setup level.