1
votes

In my Xamarin.Forms 4.4 project, I had defined the global colors for my navigation bar to be a solid orange with white text using the following code::

UINavigationBar.Appearance.BackgroundColor = UIColor.Orange;
UINavigationBar.Appearance.BarTintColor = UIColor.Orange;
UINavigationBar.Appearance.TintColor = UIColor.White;
UINavigationBar.Appearance.TitleTextAttributes = new UIStringAttributes()
{
  ForegroundColor = UIColor.White
};

Since upgrading my Xamarin.Forms NuGet package from 4.4 to 4.5, any app I run in iOS 13 has a solid white navigation bar in Light Mode with white text.

I know that there are some new classes to use for iOS 13. But, I don't understand is how to use these to get the same appearance, (or just something readable) in iOS 13. Here is what I have tried:


  UINavigationBarApperance nba = new UINavigationBarAppearance();
  nba.ConfigureWithOpaqueBackground();
  nba.BackgroundColor = UIColor.Orange;
  nba.BarTintColor = UIColor.Orange;
  nba.TintColor = UIColor.White;
  UINavigationBar.Appearance.ScrollEdgeAppearance = nab;
  UINavigationBar.Appearance.StandardAppearance = nab;
  UINavigationBar.Appearance.CompactAppearance = nab;

Here are my results:

I can actually see some color bleeding through what appears to be a white gradient overlay. I suspect the dark grey is a result of a dark gradient over my chosen color

enter image description here enter image description here

1
Xamarin uses the same iOS APIs that native XCode solutions do. See also github.com/xamarin/xamarin-macios/issues/6834Jason
I just tried your code in a blank Forms iOS app and it worked. However, if I try it in an existing Forms app that customizes the nav bar from the Forms code it does NOT work. Are you sure you're not doing anything in the Forms code that would effect the nav bar?Jason
You can share some Xaml code about NavigationPage in Xamarin.Forms, it will be helpful to find where problem is .Junior Jiang

1 Answers

2
votes

I have tried with shared code , there is no problem in my local site no mattter in Xamarin.iOS or Xamarin.Forms project .Effect as follow :

enter image description here

Using shared code need to write in AppDelegate.cs .If writing in other place ,such as in Sub-ViewController, will not work .

// application events from iOS.
[Register("AppDelegate")]
public partial class AppDelegate : global::Xamarin.Forms.Platform.iOS.FormsApplicationDelegate
{
    //
    // This method is invoked when the application has loaded and is ready to run. In this 
    // method you should instantiate the window, load the UI into it and then make the window
    // visible.
    //
    // You have 17 seconds to return from this method, or iOS will terminate your application.
    //
    public override bool FinishedLaunching(UIApplication app, NSDictionary options)
    {
        global::Xamarin.Forms.Forms.Init();
        global::Xamarin.Forms.FormsMaterial.Init();

        LoadApplication(new App());

        Console.WriteLine("------13--------");
        UINavigationBar.Appearance.BackgroundColor = UIColor.Orange;
        UINavigationBar.Appearance.BarTintColor = UIColor.Orange;
        UINavigationBar.Appearance.TintColor = UIColor.White;
        UINavigationBar.Appearance.TitleTextAttributes = new UIStringAttributes()
        {
            ForegroundColor = UIColor.White
        };

        return base.FinishedLaunching(app, options);
    }
}

In addition , from shared screenshot , the color has been setted for NavigationBar . However , it was overrided with other color .I think there are somewhere code written affects this .

By the way , there are methods of Xamarin Forms to set color for Navigation Bar . You also can use this or check whether already uesd it in project .

App.xaml.cs :

NavigationPage navigationPage = new NavigationPage(new MainPage());
navigationPage.BarBackgroundColor = Color.White;
navigationPage.BarTextColor = Color.Black;
MainPage = navigationPage;