iOS Question [SOLVED] How to set color of status bar?

Sandman

Well-Known Member
Licensed User
This is regarding me making my own navbar (see this thread for more info).

Normally the status bar piggybacks on the color of the navigation bar. In my case I'm building my own navigation bar, which means I'm hiding the real one. And when I hide the real one, the status bar doesn't pick up the (disabled) navigation bar color.

Which brings me to my question: How to set the color (both background and text color) of the status bar?

I found a web page showing how to do this (at least the background) using Swift, but I don't really grasp how to turn this into B4i code... :-/

This is the Swift code:
B4X:
UIApplication.shared.statusBarView?.backgroundColor = UIColor.white

And here are some examples from that page, showing different results:







 

Erel

Administrator
Staff member
Licensed User
B4X:
Dim no As NativeObject = App
no.GetField("statusBar").SetField("backgroundColor", no.ColorToUIColor(Colors.Red))
You probably need to add this line as well:
B4X:
#PlistExtra: <key>UIViewControllerBasedStatusBarAppearance</key><false/>
 

Sandman

Well-Known Member
Licensed User
That worked perfectly, thanks!

(And no, I didn't need the PlistExtra.)
 

Sandman

Well-Known Member
Licensed User
A follow-up to people finding this thread:

As I'm using a somewhat dark color for my status bar, I needed to change the black status bar text color to make it readable. Apple only allows this text to be either black or white, and thanks to this post by @JanPRO, I learned that it can be controlled using PlistExtra in B4i:

B4X:
#PlistExtra:<key>UIStatusBarStyle</key>
#PlistExtra:<string>UIStatusBarStyleLightContent</string>

#PlistExtra:<key>UIViewControllerBasedStatusBarAppearance</key>
#PlistExtra:<false/>
And this is where we do need the key that Erel posted about in #2. (If one leaves it out, the app crashes.)
 
Top