19

I am unable to change the status bar text color of my Xamarin Forms iOS app to white. I have change in my info.plist as follow:

<key>UIStatusBarStyle</key>
<string>UIStatusBarStyleLightContent</string>
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>

Yet the color still remain black.. Is there another way to change the status bar text color?

Huby03
  • 801
  • 2
  • 14
  • 28

5 Answers5

44

In Xamarin.Forms, there are three things you need to do to achieve white text in the iOS Status Bar. I've also posted a sample Xamarin.Forms app below that uses white text in the iOS Status Bar.

1. Update the Info.plist

In Info.plist, add the Boolean Property View controller-based status bar appearance and set its value to No

enter image description here

2. Use a NavigationPage & Set the Navigation Bar Text Color to White

In the Application class (typically App.cs), the MainPage must be a NavigationPage, and the BarTextColor must be set to Color.White enter image description here

3. Clean & Rebuild the App

Sometimes the compiler doesn't update the Status Bar Color until you Clean and Rebuild the app, so after making the changes in steps 1 & 2, clean the app and rebuild it. enter image description here

Sample App

https://github.com/brminnick/SaveImageToDatabaseSampleApp/

Community
  • 1
  • 1
Brandon Minnick
  • 13,342
  • 15
  • 65
  • 123
  • 1
    Thank you for your answer! But now i don't have a status bar anymore :/ – Huby03 Jun 01 '17 at 14:51
  • Oh no! Do you mind asking that as a new question on StackOverflow and sending me the link? I can post some screenshots to help you debug that problem too – Brandon Minnick Jun 01 '17 at 15:05
  • Hey, here you go: https://stackoverflow.com/questions/44321309/xamarin-ios-status-bar-text-color Thank you – Huby03 Jun 02 '17 at 05:18
  • 2
    The actual values to go into Info.plist (for example for windows users): UIViewControllerBasedStatusBarAppearance – Inrego Nov 15 '18 at 13:52
  • I had to change the info.plist directly. The change in the editor did not seem to affect the file. This could be a bug in Visual Studio for Mac. – Chucky Jul 11 '19 at 11:55
4

The only way to change status bar in IOS for me was to use this code in FinishedLaunching in AppDelegate

public override bool FinishedLaunching(UIApplication app, NSDictionary options)
{
    global::Xamarin.Forms.Forms.Init ();

    LoadApplication (.....);
    app.SetStatusBarStyle(UIStatusBarStyle.LightContent, true);

    return base.FinishedLaunching (app, options);
}
Brandon Minnick
  • 13,342
  • 15
  • 65
  • 123
Renzo Ciot
  • 3,746
  • 2
  • 25
  • 29
  • 3
    This method is deprecated: https://developer.apple.com/documentation/uikit/uiapplication/1622923-setstatusbarstyle – Domysee Apr 07 '18 at 12:25
  • @Singapore you have to change "View controller-based status bar appearance" to false in info.plist (as shown in the accepted answer). – flocbit May 18 '18 at 10:55
  • I had to change the info.plist directly. The change in the editor did not seem to affect the file. This could be a bug in Visual Studio for Mac. – Chucky Jul 11 '19 at 11:54
4

So what I did for changing status bar color and status bar text color is:

Info.plist

<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
<!--<key>UIStatusBarHidden</key>-->
<!--<true/>-->

AppDelegate

Inside function FinishedLaunching(), add code below:

UIView statusBar = UIApplication.SharedApplication.ValueForKey(new NSString("statusBar")) as UIView;
if (statusBar != null && statusBar.RespondsToSelector(new ObjCRuntime.Selector("setBackgroundColor:")))
{
    statusBar.BackgroundColor = Color.FromHex("#7f6550").ToUIColor(); // change to your desired color 
}

App.xaml

I added code below to change status bar text color to White.

<Style TargetType="{x:Type NavigationPage}">
     <!--<Setter Property="BarBackgroundColor" Value="Black" />-->
     <Setter Property="BarTextColor" Value="White" />
</Style> 
Wei Loon Wong
  • 450
  • 1
  • 7
  • 23
  • 1
    Be careful: UIView statusBar = UIApplication.SharedApplication.ValueForKey(new NSString("statusBar")) as UIView; cause exception since iOS 13 (iPhone 11, for example), check OS version before use it. UIDevice.CurrentDevice.CheckSystemVersion(13, 0) – Makeman Apr 24 '21 at 08:05
0

Select the NavigationBar and change the Style property to Black.

enter image description here

Domysee
  • 12,718
  • 10
  • 53
  • 84
0

In my case, adding this to AppDelegate FinishedLaunching worked:

UIApplication.SharedApplication.StatusBarStyle = UIStatusBarStyle.LightContent;
Prashant Agarwal
  • 729
  • 7
  • 23