iOS: Change the Orientation of the Status Bar

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 comment

Your email address will not be published. Required fields are marked *


This site uses Akismet to reduce spam. Learn how your comment data is processed.