Home > Net >  Navigation bar colour change issue in Xamarin.forms in iOS platform after iOS 15 update
Navigation bar colour change issue in Xamarin.forms in iOS platform after iOS 15 update

Time:10-06

In the application I developed, the navigation bar at the bottom of the screen, changes its color between black and white depending on the theme selected by the user. It worked perfectly all this time until I updated the software to iOS 15. Now, even if the user changes it to dark mode, the navigation bar alone stays white (supposed to turn black). Any idea why this happens? This issue only persists in iOS platform.

CodePudding user response:

This is a known issue that we are tracking here. A workaround is mentioned in there in the form of a custom renderer, I will paste it here but this is specific to Shell though. But it might give you some hint on how to use it on regular components as well.

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;
        }
        
    }
}

The issue seems to be caused by compiling against Xcode 13/running on iOS 15. Other peoples in the linked issue have mentioned that downgrading their Xcode made it work for them.

TL;DR: we're working on a fix that should be released soon :)

  • Related