IOS上工具栏项目中的图像为白色(Xamarin表单) [英] Image in Toolbar item on iOS are white(Xamarin Forms)

查看:0
本文介绍了IOS上工具栏项目中的图像为白色(Xamarin表单)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨, 我有Xamarin Forms项目,在Andorid和UWP上的工具栏项工作正常,但在iOS上是白色图像。你能帮我吗?

我的XAML代码:

ContentPage.ToolbarItems
            ToolbarItem 
                         Priority="0"
                         Order="Primary" Command="{Binding PrikaziInfoFilteriCommand}"
                ToolbarItem.Icon
                    OnPlatform x:TypeArguments="FileImageSource"
                        OnPlatform.Android
                            FileImageSource File="greenifnromation.png"
                        OnPlatform.Android

                        OnPlatform.iOS
                            FileImageSource  File="greenifnromation.png" 
                        OnPlatform.iOS
                        OnPlatform.WinPhone
                            FileImageSource File="Assets/greenifnromation.png" 
                        OnPlatform.WinPhone

                    OnPlatform
                ToolbarItem.Icon

            ToolbarItem
            ToolbarItem Icon="{Binding ImageSourceKalendarPlusMinus}"            
                         Priority="0" 
                     Order="Primary" Command="{Binding PrikaziCommand}"

            ToolbarItem
        ContentPage.ToolbarItems

推荐答案

iOS的工具栏项目默认为白色,这就是为什么它不会以您想要的方式显示。不幸的是,您将不得不创建一个iOS导航呈现器。让它覆盖NavigationPage,然后添加以下代码:

public override void PushViewController(UIViewController viewController, bool animated)
    {
        base.PushViewController(viewController, animated);

        var currentPage = (this.Element as Xamarin.Forms.NavigationPage)?.CurrentPage;

        if (this.NavigationBar == null || currentPage == null)
            return;

        var buttonItems = TopViewController.NavigationItem.RightBarButtonItems;

        foreach (var button in buttonItems)
        {
            button.Image = button.Image.ImageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal);
            button.TintColor = UIColor.Clear;
        }
    }

这篇关于IOS上工具栏项目中的图像为白色(Xamarin表单)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆