Search code examples
objective-ciosmodalviewcontrolleruiappearanceuiactivityviewcontroller

Change Appearance of Modal UIActivityViewController


How do I change the appearance of the navigation bar of a UIActivityViewController mail compose object used in a modal sharing action?

UINavigationBar - Wrong Tint

UIActivityViewController conforms to UIAppearance, so I thought the following does work but it doesn't. The navigation bar stays default blue.

activityVC.navigationController.navigationBar.tintColor = [UIColor greyColor];

Context:

    - (IBAction)share {
        NSString *textToShare = ...;
        NSURL *url = ...;

        NSArray *activityItems = [[NSArray alloc]  initWithObjects:textToShare,url,nil];

        UIActivity *activity = [[UIActivity alloc] init];
        NSArray *applicationActivities = [[NSArray alloc] initWithObjects:activity, nil];
        UIActivityViewController *activityVC =
        [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:applicationActivities];
        [activityVC setExcludedActivityTypes:[NSArray arrayWithObjects:                                              UIActivityTypeMessage,UIActivityTypeCopyToPasteboard,
UIActivityTypeAssignToContact,UIActivityTypePostToWeibo,                                              UIActivityTypePrint,UIActivityTypeSaveToCameraRoll,
                                              nil]];

        activityVC.navigationController.navigationBar.tintColor = [UIColor greyColor];

        [self presentViewController:activityVC animated:YES completion:nil];
    }

How can I change the tint of the UINavigationBar from blue to grey.


Solution

  • Do this in your Application Delegate it will change the color of navigation bar throughout the application where ever navigation bar is shown

    [[UINavigationBar appearance] setTintColor:[UIColor colorWithRed:.9 green:.9 blue:.9 alpha:1]];
    

    you can also change the text color and font using this in your Application Delegate

    NSDictionary *navbarTitleTextAttributes = [NSDictionary dictionaryWithObjectsAndKeys:
                                               [UIColor redColor],UITextAttributeTextColor,
                                               [UIFont fontWithName:@"Arial" size:19],UITextAttributeFont,
                                               nil];
    [[UINavigationBar appearance] setTitleTextAttributes:navbarTitleTextAttributes];