1
votes

I have Xamarin Forms app. I don't use NavigationBar:

Xamarin.Forms.NavigationPage.SetHasNavigationBar(this, false);

I need change color(background) and text color in status bar for iOS. I use this code:

if (UIDevice.CurrentDevice.CheckSystemVersion(13, 0))
        {
            UIView statusBar = new UIView(UIApplication.SharedApplication.KeyWindow.WindowScene.StatusBarManager.StatusBarFrame);
            statusBar.BackgroundColor = UIColor.White;
            statusBar.TintColor = UIColor.Black;
            statusBar.AccessibilityIgnoresInvertColors = true;
            statusBar.TintColorDidChange();
            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.White;
                statusBar.TintColor = UIColor.Black;
                UIApplication.SharedApplication.StatusBarStyle = UIStatusBarStyle.BlackOpaque;
            }
        }

and I added this code in my info.plist:

<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>

after this: statusbar background code - white. But text color is white(I need black color). Any advices?

1
As far as I know you can have only white or black color.Ivan Ičin
I need black color. I edited my answer.FetFrumos
@FetFrumos Hi , if answer be helpful , thanks for marking or voting up when you have time in advance *.^Junior Jiang

1 Answers

2
votes

after this: statusbar background code - white. But text color is white(I need black color). Any advices?

In iOS , you can change UIStatusBarStyle to modifiy the text color of status bar .There are three types of style , actually two types of style .(The default is dark , the same with dark style.)

  • UIStatusBarStyleDefault : A dark status bar, intended for use on light backgrounds.

  • UIStatusBarStyleLightContent : A light status bar, intended for use on dark backgrounds.

  • UIStatusBarStyleDarkContent : A dark status bar, intended for use on light backgrounds.

If need to set black text color of Status Bar in iOS, you can add the follow key-value in Info.plist .

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