Status bar

April 28th, 2009 by Chris Leave a reply »

Status bar is a tiny rectangle ( 320 x 20 px) on top of your screen, showing you you carrier’s name, range, time and battery status.

statusbar

This part is very useful while developing applications – utilities, but as far as I remember, when I started programming I was really confused how to hide it.

While designing the view in Interface Builder in view’s attributes tab you can set Status Bar = None, but it’s still there. Nothing will happen if you set Status Bar property for MainWindow.xib.

If you would like to get rid of status bar you must do it in Xcode. It’s just a single line of code:

	[[UIApplication sharedApplication] setStatusBarHidden:YES animated:NO];
It will make the status bar vanish. If you want to remove it via alpha transition set animated:YES. If you don’t want to have status bar anywhere in whole your application, you should do it in implementation of AppDelegate file ([project_name]AppDelegate.m) before you will add any subviews to the window, for example:
- (void)applicationDidFinishLaunching:(UIApplication *)application {    
	MyView *viewController = [[MyView alloc] initWithNibName:@"MyView" bundle:[NSBundle mainBundle]];
	[window addSubview:[viewController view]];
	// Override point for customization after application launch
	[window makeKeyAndVisible];
}

Status bar’s styles

By default status bar is gray – shown as an image example above. You can quickly change it, so it will be like in Springboard (black) or during YouTube video playback (black translucent – showing what’s behind him).

barblack

bartranslucent

Code:

	[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleBlackOpaque animated:YES];
	[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleBlackTranslucent animated:YES];
	[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault animated:YES];

As before using animated boolean property you can change the status bar with transition or without.

Orientation

There is another article about handling interface autorotation, but changing the status bar orientation is easy.

	[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeLeft animated:YES];
	[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight animated:YES];
 	[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait animated:YES];
	[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortraitUpsideDown animated:YES];

Please note: Using iPhone Simulator changing the orientation of status bar, automatically turn the defice to landscape / portrait mode, without changing the interface orientation (how to handle this, I will present in another tutorial).

That’s it. Sample project for you.

statusbarsimulator

xcodeproj

Download the project

Advertisement

Leave a Reply