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

后端 未结 9 2373
孤独总比滥情好
孤独总比滥情好 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: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

    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.

提交回复
热议问题