The correct way to set a light status bar text color in iOS 7 based on different ViewControllers

后端 未结 8 1248
死守一世寂寞
死守一世寂寞 2020-12-25 14:52

I need to let a specific ViewController embedded in an UINavigationController to have light status bar text color (but other ViewControllers to beh

8条回答
  •  悲哀的现实
    2020-12-25 15:11

    For your first solution, I don't think you can change the status bar in viewDidLoad. If you have two ViewControllers stacked on top of each other, and each one toggles the status bar differently, that method will only get called once for each. You really want to change the status bar in viewWillAppear so that it gets called each time the page is shown. I also don't think you can rely on preferredStatusBarStyle since I'm also not sure how often/when that gets called. This is how you want to do it:

    - (void) viewWillAppear:(BOOL)animated
    {
        [super viewWillAppear:animated];
    
        [self.navigationController.navigationBar setBarStyle:UIBarStyleDefault];
    }
    

提交回复
热议问题