1
votes

Since iOS13‘s darkmode i‘m working on supporting it in my Xamarin.Forms application. Everything works fine beside the StatusBar color when a NavigationBar is displayed. The usual behaviour of the Bar should be to change backgroundColor accordingly to the BGColor of the Navbar, but for some reason it always stays white. I‘ve tried coloring it manually like this

UIView statusBar = UIApplication.SharedApplication.ValueForKey(new NSString("statusBar")) as UIView; statusBar.BackgroundColor = UIColor.FromRGB(61, 205, 88);

But it didn‘f change anything. Below a screenshot of how it looks

screenshot

1
If answer be helpful , remember to mark ot vote up later when have time.Thanks in advance :)Junior Jiang

1 Answers

3
votes

In Xamarin.Forms Application , modifying Status Bar need to edit Info.plist in iOS solution .

First, Add UIViewControllerBasedStatusBarAppearance to file :

<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
//Follow can change text color of status bar
//<key>UIStatusBarStyle</key>
//<string>UIStatusBarStyleDarkContent</string>

Second, in Xamarin.iOS project , you can modify statsbar background in AppDelegate.cs as follow :

public override void OnActivated(UIApplication uiApplication)
{
    if (UIDevice.CurrentDevice.CheckSystemVersion(13, 0))
    {
        // If VS has updated to the latest version , you can use StatusBarManager , else use the first line code
        // UIView statusBar = new UIView(UIApplication.SharedApplication.StatusBarFrame);
        UIView statusBar = new UIView(UIApplication.SharedApplication.KeyWindow.WindowScene.StatusBarManager.StatusBarFrame);
        statusBar.BackgroundColor = UIColor.Red;
        statusBar.TintColor = UIColor.White;
        UIApplication.SharedApplication.KeyWindow.AddSubview(statusBar);
    }
    else
    {
        UIView statusBar = UIApplication.SharedApplication.ValueForKey(new NSString("statusBar")) as UIView;
        if (statusBar.RespondsToSelector(new ObjCRuntime.Selector("setBackgroundColor:")))
        {
            statusBar.BackgroundColor = UIColor.Red;
            statusBar.TintColor = UIColor.White;
            UIApplication.SharedApplication.StatusBarStyle = UIStatusBarStyle.BlackOpaque;
        }
    }
    base.OnActivated(uiApplication);
}

You can also have a look at this discussion .