【问题标题】:Xamarin IOS: Change tint color in share windowXamarin IOS:在共享窗口中更改色调颜色
【发布时间】:2015-10-07 22:39:44
【问题描述】:

我正在使用此代码在 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.");
    }

当我选择邮件时,我被重定向到这里http://take.ms/3KE4F。但是取消和发送按钮的颜色是白色的(在 NavigationBar 中)。如何更改此按钮的文本颜色?

我找到了文章 Cannot set text color of Send and Cancel buttons in the mail composer when presented from the UIActivityViewController in iOS7。但不知道如何使用 Xamarin 应用它。

感谢您的帮助。

【问题讨论】:

    标签: ios mobile xamarin xamarin.ios


    【解决方案1】:

    试试这个:

    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.");
    }
    

    您基本上在呈现控制器之前设置按钮色调,然后将其设置回完成处理程序。

    【讨论】:

    • 感谢您的帮助,但问题是根据应用程序设计,导航栏中的文本对于整个应用程序来说应该是白色的,但是当它共享屏幕时,它使用具有灰色操作栏的标准 ios 屏幕,并且白色文本不再在那里工作。有没有只为共享屏幕更改颜色?
    • 是的,我不得不在我的一个应用程序中做类似的事情,用我采取的解决方案更新了我的答案。
    • 你摇滚。非常感谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-10-15
    • 1970-01-01
    • 2018-05-06
    • 1970-01-01
    • 2023-01-12
    • 2022-12-16
    • 2013-09-28
    相关资源
    最近更新 更多