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

Henry Glendening picture Henry Glendening · Nov 5, 2013 · Viewed 7.9k times · Source

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 the text/tint color of the Cancel and Send navigation bar buttons. For the bar buttons, in the AppDelegate I've tried using:

    [[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];

And nothing happens. However I am able to set the navigation bar title with this:

    [[UINavigationBar appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor], UITextAttributeTextColor, nil]];

I set the UIViewControllerBasedStatusBarAppearance to NO in the Info.plist. And put the line:

    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];

in the AppDelegate, and have had no luck changing the status bar color at all. Any ideas?

Answer

Mike Seghers picture Mike Seghers · Jul 23, 2014

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.