Hide the status bar on iPhone on a single view?

43,311

Solution 1

Try This one It will Run perfectly..

[[UIApplication sharedApplication] setStatusBarHidden:YES];

And in XIB set none option for the status bar.

for iOS 7.

Go to info.plist and add two attributes if not present. set "Status bar is initially hidden" to "YES" and set "UIViewControllerBasedStatusBarAppearance" to "NO". This will hide status bar for your app.

Solution 2

#pragma mark - Hide statusbar

-(void)hideStatusBar {
#if __IPHONE_OS_VERSION_MIN_REQUIRED >= 70000
    // iOS 7.0 or later
    [self setNeedsStatusBarAppearanceUpdate];
#else
    // less than 7
    [[UIApplication sharedApplication] setStatusBarHidden:YES];
#endif
}

- (BOOL)prefersStatusBarHidden {
    return YES;
}

Solution 3

If there is anyone looking for a solution where the above solution does not work (and there is still an annoying blue 20px gap at the top), try putting this in the viewWillAppear on the implementation file of the view controller that you would like the status bar to be hidden.

self.navigationController.navigationBar.frame = CGRectOffset(self.navigationController.navigationBar.frame, 0.0, -20.0);

That literally took me 12 hours or so to fix, and that was the solution, so now i'm spreading the word in case anyone else has this annoying issue.

Solution 4

Kartik's solution worked for me.

[[UIApplication sharedApplication] setStatusBarHidden:YES];

I added this to viewWillAppear: instance method.

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [[UIApplication sharedApplication] setStatusBarHidden:YES];
    self.webView.scalesPageToFit = YES;
    [self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.google.co.uk"]]];
}

And I spent ages on this too. Using Xcode 4.2, iOS5 sim.

But when I first implemented it, the annoying "space" at the top was there. I selected the View Controller in the storyboard and set the properties as follows: Size: Full Screen StatusBar: None everything else inferred.

I checked wants full screen.

Voila, it all worked fine.

Solution 5

I know this is an old question but none of this answers works for me, so this is how it works for me to hide the status bar in a single viewController

First in your parentViewController you have to set:

- (UIViewController *)childViewControllerForStatusBarHidden {
    if ( hideStatusBarViewController ) {
        return hideStatusBarViewController;
    }
    return nil
}

It only returns the child view controller when its created otherwise nil is the default. When you add your hideStatusBarViewController you must call

[self setNeedsStatusBarAppearanceUpdate];

on the parentViewController, this function forces to read childViewControllerForStatusBarHidden. Finally in hideStatusBarViewController you must set

- (BOOL)prefersStatusBarHidden {
    return YES;
}

Its the only solution that works for me. I hope it help somebody.

Share:
43,311
Adam Waite
Author by

Adam Waite

I make iOS apps in East London. I make web apps occasionally too, mainly with Rails and JS.

Updated on February 14, 2020

Comments

  • Adam Waite
    Adam Waite over 4 years

    I want to show the status bar in my app in all views but one. I have tried modifying the 'status bar is initially hidden' in the plist, i have tried:

    [[UIApplication sharedApplication] setStatusBarHidden:YES];
    

    That hides the bar but leaves an ugly blue box where the status bar was (which isn't part of my view, there's nothing blue on there).

    I have also tried altering the layout wants full screen and status bar settings in the 'interface builder' bit of Xcode 4.2.

    Any suggestions?

    EDIT - SORT OF SOLUTION:

    I have done it by including:

        -(void)viewWillDisappear:(BOOL)animated{
    
    
        [[UIApplication sharedApplication] setStatusBarHidden:YES];
    
    }
    
    
    -(void)viewDidAppear:(BOOL)animated{
    
    
        [[UIApplication sharedApplication] setStatusBarHidden:NO];
    
    }
    

    on every single page that I want the status bar to be on.

    It still looks choppy and rubbish because the tab bar appears and reappears each time you switch a view. But i've had enough, worked on this stupid problem for about 5 hours now so this will have to do.

    SECOND EDIT -

    Fixed the choppyness by including setStatusBarHidden=NO in viewWillAppears. God knows how everything works but it does.