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

Discussion in 'iOS Questions' started by Sandman, Nov 7, 2018.

  1. Sandman

    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:
    UIApplication.shared.statusBarView?.backgroundColor = UIColor.white

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




  2. Erel

    Erel Administrator Staff Member Licensed User

    Dim no As NativeObject = App
    "statusBar").SetField("backgroundColor", no.ColorToUIColor(Colors.Red))
    You probably need to add this line as well:
    #PlistExtra: <key>UIViewControllerBasedStatusBarAppearance</key><false/>
    JordiCP, Alexander Stolte and Sandman like this.
  3. Sandman

    Sandman Well-Known Member Licensed User

    That worked perfectly, thanks!

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

    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:


    And this is where we do need the key that Erel posted about in #2. (If one leaves it out, the app crashes.)
    ilan, Alexander Stolte and Erel like this.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice