3.9. Status Bar Manipulation

The status bar's appearance can be customized to meet the look and feel of your application, or you can remove it entirely if you need the extra screen real estate. The changes you make to the status bar will only affect your application; the standard status bar will bounce back when you press the Home button.

You can change many properties of the status bar using methods from the UIApplication class. The UIApplication class represents your running application. To gain access to this object, use the class's static sharedApplication method:

UIApplication *myApp = [ UIApplication sharedApplication ];

3.9.1. Hiding the Status Bar

To hide the status bar entirely, use the setStatusBarHidden method:

[ myApp setStatusBarHidden: YES animated: YES];

If you're going to do this, be sure to hide the status bar before creating any windows or views. Otherwise, the application frame will not include the space taken up by the status bar, and you'll have to reset any affected view classes using the setFrame method:

 

[ viewController.view setFrame: [ [ UIScreen mainScreen ] applicationFrame ] ];

[ [ navigationController view ]
    setFrame: [ [ UIScreen mainScreen ] applicationFrame ]
];

                                          

3.9.2. Status Bar Style

The status bar style determines its color and opacity. The status bar style sets the overall appearance of the bar:

[ myApp setStatusBarStyle: UIStatusBarStyleBlackOpaque ];

The following styles are supported.

Style Description
UIStatusBarStyleDefault Default; white status bar with black text
UIStatusBarStyleBlackTranslucent Black transparent status bar with white text
UIStatusBarStyleBlackOpaque Black opaque status bar with white text

3.9.3. Status Bar Orientation

Normally, the orientation of the status bar is changed automatically when using view controllers. To force the orientation of the status bar, use the UIApplication class's setStatusBarOrientation method:

[ myApp setStatusBarOrientation: UIInterfaceOrientationLandscapeRight
    animated: NO
];

The following orientations are available on the device.



UIDeviceOrientationPortrait

Oriented upright vertically in portrait mode



UIDeviceOrientationPortraitUpsideDown

Oriented upside-down vertically in portrait mode



UIDeviceOrientationLandscapeLeft

Device is rotated counter-clockwise in landscape mode



UIDeviceOrientationLandscapeRight

Device is rotated clockwise in landscape mode



UIDeviceOrientationFaceUp

Device is laying flat, face up, such as on a table



UIDeviceOrientationFaceDown

Device is laying flat, face down, such as on a table