在iOS 15更新后,Xamarin.forms中导航栏颜色更改存在问题。

3
在我开发的应用程序中,屏幕底部的导航栏会根据用户选择的主题在黑色和白色之间变换颜色。一直以来都运作良好,直到我把软件升级到iOS 15后才出现问题。现在,即使用户将其更改为暗模式,导航栏也仍然保持白色(本该变成黑色)。你知道为什么会出现这种情况吗?这个问题只存在于iOS平台上。

尝试更改 NavigationBar.View.BackgroundColor 或 NavigationBar.ScrollEdgeAppearance.BackgroundColor。 - Le-roy Staines
2个回答

5

更新 2:当前版本(撰写本文时为5.0.0.2244)应该已经解决了这个问题。

更新:修复已合并,即将发布!

这是一个我们正在跟踪的已知问题,可以在此处找到。其中提到了一种自定义渲染器的解决方法,我会把它粘贴在这里,但是这只适用于Shell。但是这可能会给你一些关于如何在常规组件上使用它的提示。

using UIKit;
using Xamarin.Forms;
using Xamarin.Forms.Platform.iOS;

[assembly: ExportRenderer(typeof(APPNAME.AppShell), typeof(APPNAME.iOS.Renderers.CustomShellRenderer))]
namespace APPNAME.iOS.Renderers
{

    public class CustomShellRenderer : ShellRenderer
    {
        protected override IShellSectionRenderer CreateShellSectionRenderer(ShellSection shellSection)
        {
            var renderer = base.CreateShellSectionRenderer(shellSection);
            
            if (renderer != null)
            {
                if (renderer is ShellSectionRenderer shellRenderer)
                {
                    
    
                    var appearance = new UINavigationBarAppearance();
                    appearance.ConfigureWithOpaqueBackground();
                    appearance.BackgroundColor = new UIColor(red: 0.86f, green: 0.24f, blue: 0.00f, alpha: 1.00f);
                    
                    appearance.TitleTextAttributes = new UIStringAttributes() { ForegroundColor = UIColor.White};
                    
              
                    shellRenderer.NavigationBar.Translucent = false;
                    shellRenderer.NavigationBar.StandardAppearance = appearance;
                    shellRenderer.NavigationBar.ScrollEdgeAppearance = shellRenderer.NavigationBar.StandardAppearance;
                    
                }
            }

            return renderer;
        }

        protected override IShellItemRenderer CreateShellItemRenderer(ShellItem item)
        {
            var renderer = base.CreateShellItemRenderer(item);
            
            if (renderer != null)
            {
                if (renderer is ShellItemRenderer shellItemRenderer)
                {
                    var appearance = new UITabBarAppearance();
                    
                    appearance.ConfigureWithOpaqueBackground();

                    shellItemRenderer.TabBar.Translucent = false;
                    shellItemRenderer.TabBar.StandardAppearance = appearance;
               
                }
                

            }

            return renderer;
        }
        
    }
}

问题似乎是由编译使用Xcode 13 / 在iOS 15上运行引起的。在相关问题中,其他人提到将Xcode降级使其正常工作。 简而言之:我们正在处理一个修复程序,很快就会发布 :)

嗨,Gerald Versluis,你能帮忙解决这个问题吗? - nevermore

1

1
对于任何人来说,我不建议使用由PR生成的NuGets作为您在生产中使用的版本。这些版本不包含我们产品中所有的更改。它们仅用于验证问题是否已解决。 - Gerald Versluis

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接