17

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?

Henry Glendening
  • 2,132
  • 2
  • 13
  • 22
  • have tried this for status bar color http://stackoverflow.com/questions/17678881/how-to-change-status-bar-text-color-in-ios-7 – the1pawan Nov 26 '13 at 04:42
  • @the1pawan I have tried that. It only changes the status bar colors for my regular UIViewControllers and has no affect on the status bar of an activity that was launched from a UIActivityViewController – Henry Glendening Jan 14 '14 at 16:37
  • 8
    I asked Apple for help on this one and they confirmed that this is a bug. I've filed a bug report, so hopefully this will get fixed in iOS 7.1. I would suggest filing a bug report as well at bugreport.apple.com and reference mine, 15959753. – Nick Feb 02 '14 at 22:57

6 Answers6

7

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.

Mike Seghers
  • 1,655
  • 2
  • 15
  • 12
  • 2
    In iOS 8 overriding `presentViewController:animated:completion` didn't work so instead I overrode `viewWillAppear` and `viewWillDissappear` to change back and forth between styles. – Luke Vella Oct 18 '14 at 10:41
  • And how status bar color refers to the question? – vahotm Jul 28 '17 at 14:49
4

Rather than sub-classing from UIActivityViewController, we can change the tintColor of the navigation bar upon presenting it and revert it upon completion in the completionHandler. For example:

UIColor *normalColor = [[UINavigationBar appearance] tintColor];
UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:dataToShare applicationActivities:nil];
[activityViewController setCompletionHandler:^(NSString *activityType, BOOL completed) {
      // back to normal color
     [[UINavigationBar appearance] setTintColor:normalColor];
}];

[self presentViewController:activityViewController animated:YES completion:^{
     // change color to suit your need
     [[UINavigationBar appearance] setTintColor:[UIColor colorWithRed:25.0f/255.0f green:125.0f/255.0f blue:255.0f/255.0f alpha:1.0f]]; // ActionSheet options' Blue color
}];
instaable
  • 3,249
  • 2
  • 22
  • 30
2

I believe the code to change the navigation bar color is this:

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

This is for changing the colours of the navigation bar buttons in iOS 7, if you might need it:

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

And this is the code if you want to change the colours of the buttons in iOS 6:

[[UIBarButtonItem appearance] setTintColor:[UIColor redColor]];

This code is also for iOS 8+ to change the bar button text color for UIActivityViewController activities (like sharing via Messages or Mail Composer).

Kevin van Mierlo
  • 8,967
  • 5
  • 39
  • 66
  • I'm developing an app for iOS 8+, and just FYI that last one (UIBarButtonItem appearance setTintColor) was needed in my app to change the bar button text color for UIActivityViewController activities (like sharing via Messages or Mail Composer). – Mason G. Zhwiti Aug 17 '15 at 17:11
  • @MasonG.Zhwiti Thanks for the response. I added it to my answer. – Kevin van Mierlo Aug 18 '15 at 07:46
2

In iOS 8 the UIActivityViewController presents its individual compose controllers on the root view controller of your application.

You need to subclass your root view controller (whether it be a UIViewController or UINavigationController) and add the following code.

@interface UINavigationControllerBarColor : UINavigationController

@end

@implementation UINavigationControllerBarColor

- (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

and then instead of initializing a UINavigationController in the AppDelegate or storyboard, initialize your newly subclassed controller.

Some other recommendations subclass the UIActivityViewController but this does not work.

If you want to change the bar button and title colors as well use the following in your application:didFinishLaunching:

[[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];
[[UINavigationBar appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
                                                      [UIColor whiteColor], UITextAttributeTextColor,
                                                      [UIFont systemFontOfSize:18.0f], UITextAttributeFont,
                                                      nil]];
[[UIBarButtonItem appearanceWhenContainedIn:[UINavigationBar class], nil] setTintColor:[UIColor whiteColor]];
Josh Bernfeld
  • 3,357
  • 2
  • 28
  • 33
  • I did what you suggest in the first part, but it never gets called. I already had my root view controller subclassed to handle `shouldAutorotate` which works well, but `presentViewController` is not being called. Any other details? – Kevin_TA Jul 02 '15 at 21:47
  • It's the root of the top most presented view controller. – mofojed Sep 04 '15 at 19:41
0

I found a solution to change the text color of the Send and Cancel buttons.

Check my answer from here.

Regarding changing the status bar style from black to white, I've tried pretty much everything that is on Stackoverflow and nothing worked. There seems to be no workaround it.

One thing that might work, but I don't really know how to use it, could be changing the status bar style in the child view controller. There's a Stackoverflow post about it here.

This might work only if the assumption that the MFMailComposerViewController and MFMessageComposeViewController are child view controllers of UIActivityViewController and therefore if we specify the status bar style for the UIActivityViewController then the child view controllers should have the same status bar style as the parent.

There's a method in the UIViewController called childViewControllerForStatusBarStyle. Here is the Apple documentation for it .

But I don't really know how to use that. Did anyone figure this out?

Community
  • 1
  • 1
Alex
  • 2,245
  • 3
  • 23
  • 33
-1

You have to set the tintColor of the entire app.

self.window.tintColor = [UIColor redColor];

or

self.navigationController.navigationBar.tintColor = [UIColor whiteColor];

bar buttons

self.navigationController.navigationBar.tintColor = [UIColor redColor];
the1pawan
  • 1,204
  • 9
  • 26