How to change UIStatusBarStyle in iOS 7 in modal views with navigation bar?

后端 未结 9 2372
孤独总比滥情好
孤独总比滥情好 2020-12-31 11:32

The iOS 7 Transition Guide give a good hint how to change the UIStatusBarStyle dynamically in a UIViewController using

- (UIStatus         


        
相关标签:
9条回答
  • 2020-12-31 12:07

    You need a ViewController that's showing in Fullscreen to return the appropriate status bar infos. In your case: The NavigationController which contains ModalViewController needs to implement preferredStatusBarStyle and return UIStatusBarStyleLightContent.

    A call to setNeedsStatusBarAppearanceUpdate is only necessary if the values a view controller returns actually change. When the view controller is first presented they are queried anyway.

    0 讨论(0)
  • 2020-12-31 12:09

    All of the above work. However sometimes I find it really a pain in the bottom to go and change every instance in the Storyboard etc... So here's something that works for me that also involves subclassing.

    First create the subclass:

    @interface HHNavLightColorBarController : UINavigationController
    
    @end
    
    @implementation HHNavLightColorBarController
    
    - (UIStatusBarStyle)preferredStatusBarStyle {
        return UIStatusBarStyleLightContent;
    }
    @end
    

    Then using the magic of Objective-C and a little bit of the <objc/runtime.h>

    When you have a reference of the view controller and your presenting it:

    UINavigationController *navVC = ...; // Init in your usual way
    object_setClass(navVC, [HHNavLightColorBarController class]);
    [self presentViewController:nav animated:YES completion:^{
        NSLog(@"Launch Modal View Controller");
    }];
    

    Sometimes it seems a bit less intrusive. You could probably even create a category that checks to see if your kindOfClass is a navigation controller and auto do it for you. Anyways, the answer is above by jaetzold, I just found this to be handy.

    0 讨论(0)
  • 2020-12-31 12:10

    Just look up if your app's rootViewController need to override -(UIStatusBarStyle)preferredStatusBarStyle method

    0 讨论(0)
提交回复
热议问题