2

I am setting status bar colour in appdelegate class as below.

- (void)transitionToViewController:(UIViewController *)viewController
                    withTransition:(UIViewAnimationOptions)transition
{
    self.window.rootViewController = viewController;

    //SET STATUS BAR COLOR
    if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7.0"))
    {
        UIView *view=[[UIView alloc] initWithFrame:CGRectMake(0, 0,[UIScreen mainScreen].bounds.size.width, 20)];
        view.backgroundColor= [UIColor colorWithRed:0.96 green:0.96 blue:0.96 alpha:1.0];
        [self.window.rootViewController.view addSubview:view];
    }
}

When I try to remove it from a single screen I am failing. It keeps the background colour as I set in appdelegate but removes texts. I want to remove also the background.

Here how I try to remove the status bar:

[[UIApplication sharedApplication] setStatusBarHidden:YES];

and status bar looks like this:

enter image description here

birdcage
  • 2,638
  • 4
  • 35
  • 58
  • Try http://stackoverflow.com/questions/8326804/hide-the-status-bar-on-iphone-on-a-single-view – Rishab May 18 '17 at 11:04
  • Possible duplicate of [Unable to hide statusbar in single UIViewController](http://stackoverflow.com/questions/36717012/unable-to-hide-statusbar-in-single-uiviewcontroller) – MAhipal Singh May 18 '17 at 11:46

2 Answers2

0

in info.plist add this View controller-based status bar appearance set YES

View controller-based status bar appearance = YES

viewcontroller based hidden set

Add method in your view controller.

Objective -C

- (BOOL)prefersStatusBarHidden {
    return YES;
}

Swift

override func prefersStatusBarHidden() -> Bool {
    return true
}
Gagan_iOS
  • 3,638
  • 3
  • 32
  • 51
-1

Add the following to your Info.plist:

<key>UIStatusBarHidden</key>
<true/>
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>

This also works (iOS7+):

override func prefersStatusBarHidden() -> Bool {
    return true
}

You also need to call:

setNeedsStatusBarAppearanceUpdate()

in say viewDidLoad().

Ved Rauniyar
  • 1,539
  • 14
  • 21