F0rc0sigan
F0rc0sigan

Reputation: 674

Xamarin IOS: Change tint color in share window

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.

Upvotes: 1

Views: 360

Answers (1)

Iain Smith
Iain Smith

Reputation: 9703

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.

Upvotes: 1

Related Questions