1

This post shows how to set the status bar color for iOS. However, I have HasNavigationBar=false on my pages, so how can I set the color for when you aren't using a nav bar?

My page...

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             NavigationPage.HasNavigationBar="false">
John Livermore
  • 30,235
  • 44
  • 126
  • 216
  • 1
    `NavigationBar` and `StatusBar` are different things. You will have to do it in the platform-specific code. There were no way to do that out of the box until XF 3.5. [This article](https://evgenyzborovsky.com/2018/08/20/dynamically-changing-the-status-bar-appearance-in-xamarin-forms/) can help you to get a try – Diego Rafael Souza Sep 17 '19 at 01:17

2 Answers2

1

You could add code to the FinishedLaunching method of your AppDelegate class within your iOS project. For example to set status bars color to some shade of green

public override bool FinishedLaunching(UIApplication app, NSDictionary options)
{
   // set status bar color to green
   UIView statusBar = UIApplication.SharedApplication.ValueForKey(new NSString("statusBar")) as UIView;
   statusBar.BackgroundColor = UIColor.FromRGB(61, 205, 88);

   // the usual suspects follow
   global::Xamarin.Forms.Forms.Init();
   LoadApplication(new App());

   return base.FinishedLaunching(app, options);
}

Hope this helps.

Mouse On Mars
  • 1,086
  • 9
  • 28
0

This AppDelegate code changes the status bar color for both iOS 13 and older iOS versions.

  public override bool FinishedLaunching(UIApplication app, NSDictionary options)
  {
        int red = 11;
        int green = 22;
        int blue = 33;

        // the usual Xamarin.Forms code
        global::Xamarin.Forms.Forms.Init();
        LoadApplication(new App());

        bool canLoadUrl = base.FinishedLaunching(app, options);

        // get status bar and set color
        UIView statusBar;
        if (UIDevice.CurrentDevice.CheckSystemVersion(13, 0))
        {
            const int tag = 999; 

            var window = UIApplication.SharedApplication.Delegate.GetWindow();
            if (window is null) return null;

            statusBar = window.ViewWithTag(tag) ?? new UIView(UIApplication.SharedApplication.StatusBarFrame)
            {
                Tag = tag
            };

            window.AddSubview(statusBar);
        }
        else
        {
            statusBar = UIApplication.SharedApplication.ValueForKey(new NSString("statusBar")) as UIView;
        }
        if (!(statusBar is null))
        {
            statusBar.BackgroundColor = UIColor.FromRGB(red, green, blue);
        }

        return canLoadUrl;
   }
Mouse On Mars
  • 1,086
  • 9
  • 28