【问题标题】:Navigation bar colour change issue in Xamarin.forms in iOS platform after iOS 15 updateiOS 15 更新后 iOS 平台 Xamarin.forms 导航栏颜色变化问题
【发布时间】:2021-11-25 11:15:47
【问题描述】:

在我开发的应用程序中,屏幕底部的导航栏会根据用户选择的主题在黑色和白色之间改变颜色。在我将软件更新到 iOS 15 之前,它一直运行良好。现在,即使用户将其更改为暗模式,单独的导航栏也会保持白色(应该变黑)。知道为什么会这样吗?此问题仅在 iOS 平台上存在。

【问题讨论】:

  • 尝试更改 NavigationBar.View.BackgroundColor 或 NavigationBar.ScrollEdgeAppearance.BackgroundColor

标签: c# ios xamarin.forms themes ios15


【解决方案1】:

更新 2:当前版本(在撰写本文时为 5.0.0.2244)应该可以解决此问题

更新:对此的修复已合并,应该很快就会发布!

这是一个已知问题,我们正在跟踪 here。其中以自定义渲染器的形式提到了一种解决方法,我将其粘贴到此处,但这仅适用于 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 使其适用于他们。

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

【讨论】:

【解决方案2】:

您好,该问题已在预发布 Xamarin 表单中修复,添加源 Nuget 以访问它 https://aka.ms/forms-prs/index.json

然后就可以安装 Xamarin Form 5.0.0.7649 包解决问题了。

要了解更多信息,请访问 GitHub 中 proyect 页面中的错误: https://github.com/xamarin/Xamarin.Forms/issues/14505

【讨论】:

  • 对于任何发现这一点的人:我不建议将 PR 产生的 NuGet 用作生产中使用的版本。这些版本不包含我们产品中的所有更改。它们仅用于验证问题是否已解决。
猜你喜欢
  • 2021-11-16
  • 1970-01-01
  • 2021-12-24
  • 2021-11-22
  • 2022-01-04
  • 1970-01-01
  • 2017-02-17
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多