Search code examples
iosobjective-cios7-statusbar

Show and hide status bar + change status bar text color between view controllers in iOS


Yet another question about the iOS 7 status bar coloring and visibility... in my solution I want to have all these things:

  • The status bar is to be hidden and shown (with animation) on a view controller in response to user actions (as they slide stuff around)
  • When a new view controller is pushed on to the navigation controller, the color of the text in the status bar should change from black to white
  • AND when the new view controller comes in, the status bar should always be shown

I'm having trouble with the 'View controller based status bar appearance' plist setting; when NO, I'm able to show and hide the status bar, but not change the color; whereas when set to YES, it's vice versa.


Solution

  • with View controller based status bar appearance to NO in plist it would work.

    For example-> Lets say in viewcontroller1, i have below piece of code

    -(void)viewDidAppear:(BOOL)animated{
        [super viewDidAppear: animated];
        [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault animated:YES];
    }
    

    And i push viewcontroller2 from viewcontroller1 which has below code

    -(void)viewDidAppear:(BOOL)animated{
        [super viewDidAppear: animated];
        [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent animated:YES];
    }
    

    with above code when tested in simulator, it perfectly animated the changes.