0

I want to hide the status bar at the click of a button. I have tried:

[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationFade];

I have had no luck with this. Am I missing something?

Shawn
  • 667
  • 8
  • 19
  • Possible duplicate: http://stackoverflow.com/questions/18059703/cannot-hide-status-bar-in-ios7 and http://stackoverflow.com/questions/19067899/how-to-hide-the-status-bar-in-programmatically-in-ios-7 – Aaron Sep 05 '14 at 21:09
  • Yeah I was just hoping there was another way. – Shawn Sep 05 '14 at 21:29
  • 1
    Check out this answer for a way to make it change when you want: http://stackoverflow.com/a/18856079/772156 – hukir Sep 05 '14 at 22:53

3 Answers3

2

The simple way is, go to the info.plist file. add row, "View controller-based status bar appearance" and set to NO. Check as an answer

2

For toggling on and off in code only:

-(void)statusBarShouldHide:(bool)hide{

    hideStatusBar = hide;
    if ([self respondsToSelector:@selector(setNeedsStatusBarAppearanceUpdate)]) {
        [self performSelector:@selector(setNeedsStatusBarAppearanceUpdate)];
    }
}
-(bool)prefersStatusBarHidden{
    return hideStatusBar;
}

called by:

[self statusBarShouldHide:true];
Johnny Rockex
  • 4,136
  • 3
  • 35
  • 55
0

if you wanna do this programmingly try this.

override the funtion

-(BOOL) prefersStatusBarHidden {
    return needHideStatusBar;
}

-(IBAction) checkStatus {

    // do your judgment here 

    needHideStatusBar = YES;
    if ([self 
        respondsToSelector:@selector(setNeedsStatusBarAppearanceUpdate)]) {
        [self performSelector:@selector(setNeedsStatusBarAppearanceUpdate)];
    }
}
Chauyan
  • 157
  • 8