1

I am using this code for sharing in Xamarin IOS:

public void Share(string title, string content)
    {
        if (UIApplication.SharedApplication.KeyWindow == null || UIApplication.SharedApplication.KeyWindow.RootViewController == null)
            return;

        if (string.IsNullOrEmpty(title) || string.IsNullOrEmpty(content))
            return;

        var rootController = UIApplication.SharedApplication.KeyWindow.RootViewController;
        var imageToShare = UIImage.FromBundle("icon_120.png");
        var itemsToShare = new NSObject[] { new NSString(content), imageToShare };
        var shareStatusController = new UIActivityViewController(itemsToShare, null)
        {
            Title = title
        };
        //shareStatusController.NavigationController.NavigationBar.TintColor = UIColor.Black;
        //rootController.NavigationController.NavigationBar.TintColor = UIColor.Black;
        //shareStatusController.NavigationBar.TintColor = UIColor.FromRGB(0, 122, 255);

        rootController.PresentViewController(shareStatusController, true, null);
        Mvx.Resolve<IAnalyticsService>().LogEvent("Share button clicked.");
    }

When i choose mail and i am redirected here http://take.ms/3KE4F. But color of cancel and send buttons is white (in NavigationBar). How can i change color of text of this button?

I found article Cannot set text color of Send and Cancel buttons in the mail composer when presented from the UIActivityViewController in iOS7. But dont know howto apply this using Xamarin.

Thanks for any help.

Community
  • 1
  • 1
F0rc0sigan
  • 676
  • 2
  • 11
  • 22

1 Answers1

1

Try this out:

public void Share(string title, string content)
{
    if (UIApplication.SharedApplication.KeyWindow == null || UIApplication.SharedApplication.KeyWindow.RootViewController == null)
        return;

    if (string.IsNullOrEmpty(title) || string.IsNullOrEmpty(content))
        return;
    //Share Barbutton tint
    UIBarButtonItem.AppearanceWhenContainedIn (new [] {typeof(UINavigationBar)}).TintColor = UIColor.Cyan;

    var rootController = UIApplication.SharedApplication.KeyWindow.RootViewController;
    var imageToShare = UIImage.FromBundle("icon_120.png");
    var itemsToShare = new NSObject[] { new NSString(content), imageToShare };
    var shareStatusController = new UIActivityViewController(itemsToShare, null)
    {
        Title = title
    };

    shareStatusController.CompletionHandler += (NSString arg1, bool arg2) => {
            // Set it back to old theme theme
            UIBarButtonItem.AppearanceWhenContainedIn (new [] {typeof(UINavigationBar)}).TintColor = UIColor.White;
    };

    rootController.PresentViewController(shareStatusController, true, null);
    Mvx.Resolve<IAnalyticsService>().LogEvent("Share button clicked.");
}

You basically set the the button tint before you present the controller then set it back in completion handler.

Iain Smith
  • 9,230
  • 4
  • 50
  • 61
  • Thanks for help, But issues is that text in navigation bar should be white for whole application according to app design, but when it goes to share screens it uses standard ios screens that have gray action bar, and white text is not working there anymore. Is there anyway to change color only for share screens? – F0rc0sigan Jul 19 '15 at 07:03
  • Yeah I had todo a similar thing in one of my apps, updated my answer with the solution I took. – Iain Smith Jul 19 '15 at 10:44
  • 1
    You rock. Thank you so much! – F0rc0sigan Jul 19 '15 at 20:23