0

I want to remove status bar from window, and add it again. My View is not in view controller's view hierarchy. It is directly added in window. Question is, while this view appear in window, I want to hide status bar from window, When I remove this view, show it again.

-(void)hideStatusBarFromWindow:(UIWindow*)window
{
    //.......
}

Note: I've searched lot, but I've found answered for only view which is added from view controller's view hierarchy. That is my view will show up independent with any of View controller. That means, I couldn't write any code in any view controller and couldn't category view controller.

I've tried this, but couldn't worked for IOS 7(only working for IOS 6)..

[[UIApplication sharedApplication] setStatusBarHidden:YES];
Mani
  • 17,549
  • 13
  • 79
  • 100
  • 1
    @NitinGohel please read my question fully. Then go ahead with mark as duplicate. – Mani Apr 22 '14 at 05:26
  • @Mani - [[UIApplication sharedApplication] setStatusBarHidden:YES]; this is working for me.. with UIImageView that stored on window. as splash screen.. – iPatel Apr 22 '14 at 05:30
  • In IOS 7, It didn't work for me. In which device, you've tested. – Mani Apr 22 '14 at 05:31
  • what is this **otherwise don't look at any question**. – Nitin Gohel Apr 22 '14 at 05:39
  • If you haven't explaination for downvoting , then why do you look at question. – Mani Apr 22 '14 at 05:42
  • here in stack overflow NO any rules like that. you can't talking like that. here anybody can down-vote who fill that question not fully suitable. or you never said like dont look at question. very rude behave. – Nitin Gohel Apr 22 '14 at 05:44
  • Also there is NO any rule like that. It is not rude behave, I'm just asking suggestion for downvotting. If you don't have comment for downvotting, then why do you do that? – Mani Apr 22 '14 at 05:47

4 Answers4

2

Try with following code: If you custom view is display at the time of app launch then this code is perfectly working for you other wise you need to manage code ([[UIApplication sharedApplication] setStatusBarHidden:YES];) as per your requirement.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    self.window.backgroundColor = [UIColor whiteColor];
    [[UIApplication sharedApplication] setStatusBarHidden:YES];
    .
    .
    .
    return YES;
}

remove it;.

-(void) removeMycustomView
{
     [[UIApplication sharedApplication] setStatusBarHidden:NO];
     .
     .
     .
}
iPatel
  • 46,010
  • 16
  • 115
  • 137
0

In info plist add new row

View controller-based status bar appearance=NO
Sunny Shah
  • 12,990
  • 9
  • 50
  • 86
0

Simply use this in your view controller.m

 -(BOOL)prefersStatusBarHidden
{
  return isStatusBarHidden;
}

-(IBAction)showHideStatusBar
{
  isStatusBarHidden = (isStatusBarHidden)?NO:YES;
  [self setNeedsStatusBarAppearanceUpdate];
}
Anand Suthar
  • 3,678
  • 2
  • 30
  • 52
-2

put this method in your viewcontroller.m file

  -(BOOL)prefersStatusBarHidden
  {
     return YES;
  }
Dipen Desai
  • 237
  • 1
  • 16