iOS 15 更新后 iOS 平台中 Xamarin.forms 中的导航栏颜色变化问题

arv*_*dhK 3 c# themes ios xamarin.forms ios15

在我开发的应用程序中,屏幕底部的导航栏会根据用户选择的主题在黑色和白色之间更改其颜色。它一直工作得很好,直到我将软件更新到 iOS 15。现在,即使用户将其更改为深色模式,导航栏本身仍保持白色(应该变成黑色)。知道为什么会发生这种情况吗?此问题仅在 iOS 平台中存在。

Ger*_*uis 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;
        }
        
    }
}
Run Code Online (Sandbox Code Playgroud)

该问题似乎是由于针对 Xcode 13 进行编译/在 iOS 15 上运行而引起的。链接问题中的其他人提到,降级他们的 Xcode 使其适用于他们。

TL;DR:我们正在研究修复,应该很快就会发布:)