3

I want to hide the status bar for specific view controllers, not for all. then I tried this,

[[UIApplication sharedApplication] setStatusBarHidden:YES]; in the `.AppDelegate.m` inside the `didfinishlaunchwithoption`  but it didn't work. and also it is deprecated.

then I tried in my viewcontroller

- (BOOL) prefersStatusBarHidden{
    return YES;
}

this also didn't work. anyone can help me with this.thnak you I don't want to use any deprecated methods here

caldera.sac
  • 4,918
  • 7
  • 37
  • 69

5 Answers5

1

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

-(BOOL)prefersStatusBarHidden
{
    return YES;
}

and call this method where you want,For example from viewDidLoad

[self prefersStatusBarHidden];
MOHAMMAD ISHAQ
  • 988
  • 7
  • 15
  • this works fine for hide status bar. but it didn't work to show status bar in specific view controller.anyway thanx – caldera.sac Jan 18 '16 at 06:56
  • @Graham check edited answer this is working perfect for me just change "UIViewControllerBasedStatusBarAppearance" to "YES" and do the other as same. – MOHAMMAD ISHAQ Jan 18 '16 at 07:17
1

Try the code below in your view controller.
Try the following method without deprication warnings:

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:NO];

}

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

Update for iOS 9
Add the following code in your viewController for hiding status bar.

- (BOOL) prefersStatusBarHidden {
    return YES;
}
Tamás Sengel
  • 55,884
  • 29
  • 169
  • 223
Aamir
  • 16,329
  • 10
  • 59
  • 65
1

I want to hide the status bar for specific view controllers, not for all.

Only the top-level view controller gets to say whether the status bar is hidden. Your prefersStatusBarHidden is not consulted because your view controller is not the top-level view controller — it has some kind of parent view controller which is in charge of the status bar.

matt
  • 515,959
  • 87
  • 875
  • 1,141
-1
Try below code in your view controller.

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [[UIApplication sharedApplication] setStatusBarHidden:YES];

}

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

Add below code to your view controller..

 - (BOOL)prefersStatusBarHidden {

   return NO;
}

If you change the return value for this method, call the setNeedsStatusBarAppearanceUpdate method.

For childViewController, To specify that a child view controller should control preferred status bar hidden/unhidden state, implement the childViewControllerForStatusBarHidden method.