iOS: Change the Orientation of the Status Bar

On June 17, 2012, in iOS, Objective C, by Dipin Krishna

Lets see how to change the orientation of the status bar programmatically in an iphone/ipad application.
There are four orientations: Portrait, PortraitUpsideDown, LandscapeLeft, LandscapeRight.
ios orientations

The UIApplication class provides a centralized point of control and coordination for applications running on iOS.

Every application must have exactly one instance of UIApplication (or a subclass of UIApplication). When an application is launched, the UIApplicationMain function is called; among its other tasks, this function creates a singleton UIApplication object. Thereafter you can access this object by invoking the sharedApplication class method.

This object has a property statusBarOrientation, which can be used to set the orientation of the status bar.
Use the code bellow given to set the orientation of the status bar:

[UIApplication sharedApplication].statusBarOrientation = UIInterfaceOrientationPortrait;
[UIApplication sharedApplication].statusBarOrientation = UIInterfaceOrientationPortraitUpsideDown;
[UIApplication sharedApplication].statusBarOrientation = UIInterfaceOrientationLandscapeLeft;
[UIApplication sharedApplication].statusBarOrientation = UIInterfaceOrientationLandscapeRight;

Hope it helps! 🙂

Leave a Reply