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

Sandman

Expert
Licensed User
Longtime 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:

1*rfiUSx1pPKw2hcL_aI3Sog.jpeg


1*wWtdaeDpLjiurPCgYS0OQQ.jpeg


1*v5JI-wZAYnOWcbWCfMlHlA.jpeg


1*JoHtVV0VbsId6EbLH5W_cg.jpeg
 

Sandman

Expert
Licensed User
Longtime 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.)
 
Upvote 0
Top