Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Remove Status Bar in "View Based Application" - iOS

This is a part of me trying to get used to working with XCode4...

OK, so i've created a new project in XCode 4 and I used the View Based Application template; I wish to build the new app as Apple intended me to use this template.

So I'm using the automatically-created-view-controller which is called from the AppDelegate (so far I haven't touched anything). Now, I want to remove the STATUS BAR. As far as I understand, what I should do, is go to the view XIB and in the Attributes Inspector set the Status Bar field to None (this is how I used to do it so far), but mercilessly when I run the application the STATUS BAR is still there (!).

I also tried to do the same thing on the mainWindow.xib file (the setting the STSTUS BAR attribute to None thing) and the app runs with this bar that blocks my view...

Anyone?

enter image description here

like image 648
Ohad Regev Avatar asked Jun 26 '11 17:06

Ohad Regev


1 Answers

If you read the "header" you will see "Simulated metrics". Those properties are only to simulate visual elements when you lay out your code with interfacebuilder.

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

If you do it in the Application Delegate you write:

    [application setStatusBarHidden:YES animated:NO];

in this method:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {...}

EDIT

http://developer.apple.com/library/ios/#documentation/uikit/reference/UIApplication_Class/Reference/Reference.html#//apple_ref/occ/instm/UIApplication/setStatusBarHidden:withAnimation:

Requested in comment, from documentation:

setStatusBarHidden:withAnimation:

Hides or shows the status bar, optionally animating the transition. - (void)setStatusBarHidden:(BOOL)hidden withAnimation:(UIStatusBarAnimation)animation Parameters

hidden

YES to hide the status bar, NO to show the status bar. animation

A constant that indicates whether there should be an animation and, if

one is requested, whether it should fade the status bar in or out or whether it should slide the status bar in or out.

Discussion

See the descriptions of the constants of the UIStatusBarAnimation type for more information. Availability

* Available in iOS 3.2 and later.

So if you are not interested in the animation part I suggest using this:

statusBarHidden

A Boolean value that determines whether the status bar is hidden. @property(nonatomic, getter=isStatusBarHidden) BOOL statusBarHidden Return Value

YES means the status bar is hidden; NO means it's visible. Availability

* Available in iOS 2.0 and later.
like image 182
LuckyLuke Avatar answered Oct 13 '22 23:10

LuckyLuke