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

后端 未结 8 1235
死守一世寂寞
死守一世寂寞 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条回答
  •  萌比男神i
    2020-12-25 15:11

    To set UIStatusBarStyle individually for each UIViewController on UINavigationController stack you have to first subclass your UINavigationController and override childViewControllerForStatusBarStyle method.

    In your UINavigationController subclass add:

    -(UIViewController *)childViewControllerForStatusBarStyle {
         return self.visibleViewController;
    }
    

    than you can set UIStatusBarStyle to whatever you want in every UIViewController using preferredStatusBarStyle method. Eg:

    -(UIStatusBarStyle)preferredStatusBarStyle {
         return UIStatusBarStyleLightContent;
    }
    

提交回复
热议问题