Modal status bar and navigation bar text colors from UIActivityViewControllers in iOS 7

后端 未结 6 1997
孤独总比滥情好
孤独总比滥情好 2021-01-01 16:50

When I\'m using a UIActivityViewController, after the user chooses an activity (such as Mail or Message), I can not change the text color for the status bar nor

6条回答
  •  独厮守ぢ
    2021-01-01 17:39

    As the UIActivityViewController presents the underlying model view controllers, we use this workaround to fix the status bar color issue:

    @interface StatusBarColorApplyingActivityViewController : UIActivityViewController
    
    @end
    
    @implementation StatusBarColorApplyingActivityViewController
    
    - (void)presentViewController:(UIViewController *)viewControllerToPresent animated:(BOOL)flag completion:(void (^)(void))completion {
      [super presentViewController:viewControllerToPresent animated:flag completion:^{
        [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
        if (completion) {
          completion();
        }
      }];
    }
    
    @end
    

    As you can see, this is just a class extending the UIActivityViewController overriding the presentViewController:animated:completion:. When the view controller has been presented we set the status bar style via UIApplication in the completion block. Then we call the original completion block given to the method, if any.

提交回复
热议问题