• The Status Bar

    19 February 2016

    The Status Bar (or UIStatusBar) is the 20-pixel-high strip at the top of the window that shows the carrier name and signal strength, network status, current time, and battery strength:

    Black Opaque
    Black Translucent

    Black and white status bars push the underlying views down, giving you 320 x 460 pixels of screen space to work with in your app. A translucent status bar overlays the underlying view, giving you the full 320 x 480 pixels of screen space. 

    You can set the status bar style either programmatically or in your Info.plist file. If you change it in Info.plist, then the style is changed when the app launches (while the app is loading). If you change it programmatically, then the style changes after the app finishes loading.

    To change the status bar style in Info.plist, look for your Appname-Info.plist file in the Resources group of your Xcode project. To add a new element to this file, click on the last line of options so that the + symbol appears on the right. Click it, then enter UIStatusBarStyle in the left column. After you set that, the right column will then change to a list of options:

    [img src="http://www.idev101.com/code/User_Interface/statusStyleSet.png" >

    To change the style programmatically after the app has launched, add this line to your app delegate's applicationDidFinishLaunching method:

     [[UIApplication sharedApplication] setStatusBarStyle: UIStatusBarStyleBlackTranslucent];

    Valid status bar styles are UIStatusBarStyleDefault, UIStatusBarStyleBlackTranslucent, and UIStatusBarStyleBlackOpaque.

    Hiding the Status Bar

    You can also hide the status bar completely, but give some consideration as to whether you should do this. From the iPhone Human Interface Guidelines: "People expect to be able to see the current battery charge of their devices; hiding this information, and requiring users to quit your application to get it, is not an ideal user experience."

    To hide the status bar when the app launches, add a new line to Info.plist and enter UIStatusBarHidden in the left column. The right column will change to a checkbox:

    applicationDidFinishLaunching method:

    [[UIApplication sharedApplication> setStatusBarHidden:YES animated:NO];

    If you set animated to YES then the status bar will disappear by fading out.


Comments closed on this post.