52

What is the proper way to implement the status bar and navigation bar that go on top of an UIView?

alt text http://img.skitch.com/20081217-t78sdixk37hqgdh1ia2fgec4st.png

6 Answers 6

45

Just set “wants fullscreen layout” in your view controller. That solves the problem for me.

self.wantsFullScreenLayout = YES;
6
  • It seems this is the most simple and effective solution. Jul 20, 2009 at 22:18
  • 3
    Set in UIViewController subclass with: self.wantsFullScreenLayout = YES;
    – petert
    Jun 21, 2010 at 11:05
  • 13
    Didn't work for me (using a UINavigationController). I had to set self.navigationController.navigationBar.translucent = YES also.
    – bentford
    Jan 14, 2011 at 8:11
  • self.wantsFullScreenLayout doesn't work for me. My vc has no navigation bar tho. Apr 5, 2012 at 19:16
  • 1
    You have to set wantsFullScreenLayout = YES of all layered VCs. If there's any intermediate VC without the setting, it won't work.
    – eonil
    Nov 3, 2012 at 8:09
23

In the screenshot above, there's a translucent status bar and a translucent navigation bar.

The status bar is set using

[[UIApplication sharedApplication] setStatusBarStyle: UIStatusBarStyleBlackTranslucent];

The navigation bar is set using

theNavigationController.navigationBar.barStyle = UIBarStyleBlackTranslucent;
5
  • how to hide the bars on the top and bottom if it is uiwebview in the view controller ??
    – thndrkiss
    Aug 19, 2010 at 19:31
  • 1
    This didn't work for me on iPhone Simulator 3.2. From the Xcode Documentation: "Deprecated. Use UIBarStyleBlack and set the translucent property to YES instead." That worked! :)
    – ma11hew28
    Sep 27, 2010 at 0:06
  • When this was written (Dec. 2008), this was the proper way. Of course, over time the API does change. Your method is now correct.
    – August
    Oct 15, 2010 at 20:18
  • As I mentioned in another comment, you may also want to set the backgroundColor property of your navigation bar if you want to match the above image.
    – zekel
    Jan 10, 2011 at 21:53
  • I also had to set translucent property to YES before it worked. Can we add this to the answer?
    – bentford
    Jan 14, 2011 at 8:10
14

If you have a view controller inside a navigation controller, and you want to hide the status bar in order to have your viewController's view in full screen, you can always call :

[self.navigationController.view setNeedsLayout];

after hiding the status bar. But I personally think

[self setWantsFullScreenLayout:YES];

is a better way.

1
  • You may also want to set the barStyle, isTranslucent, and backgroundColor properties of your navigation bar if you want to match the above image.
    – zekel
    Jan 10, 2011 at 21:52
4

The best way I came up was this: when using a "complex" hierarchy of Tab bar containing navigation controllers, with one "detail" view being a full screen view.

In the app delegate just before the tab bar controller's view is added to the window, I added this:

tabBarController.view.frame = [[UIScreen mainScreen] bounds];

This will make the tab bar controller cover the entire screen, even below the area of the status bar. I had to offset heights of several views to +20px, notably the navigation bars.

1
  • Given the situation of the O/P I have no doubt that this solution works. However, this solution is not very general. If the tabBarController.view is the subview of a view that is not itself a full screen view this solution will not work. Or the paraphrase, the bounds rect has (0,0) as it's origin, so your tabBarController.view will have it's origin point as the same origin of the super view.
    – SooDesuNe
    Dec 10, 2009 at 4:59
0

Set the statusbar style as black translucent and navigation bar style as black translucent. If you are using a navigation-based application, in the MainWindow.xib check the status bar is hidden and navigation bar is hidden checkboxes.

When the user touches the screen, start a timer to see if this was a single tap or double tap. If a single tap, make the statusbar and navbar hidden = NO. and once user activity stops, start a timer again. after some time of no activity, make them hidden again.

0

step 1 Set the UIViewControllerBasedStatusBarAppearance to No in the plist

Then add the following code in did finish launch option

if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7) {

   [application setStatusBarStyle:UIStatusBarStyleLightContent];

    self.window.clipsToBounds =YES;

    self.window.frame =  CGRectMake(0,20,self.window.frame.size.width,self.window.frame.size.height-20);
}

Please follow this code it worked for me

Not the answer you're looking for? Browse other questions tagged or ask your own question.