Search code examples
c#.netmauimaui-community-toolkit

How do you set the status bar color for iOS with platform specific code on .NET MAUI?


I am looking to set the status bar color for iOS on .NET MAUI. I have tried a combination of Community Toolkit (Current bug where release builds of Android crash on startup), Background Color and Background (Both not respected by iOS on startup) and setting the color myself on a shape I drew behind the status bar and that didn't work to well, a little finicky with device orientation. I have tried googling and have not found much on how to use UIKit to set the color. Any help is much appreciated.


Solution

  • You can use .NET MAUI CommunityToolkit package to set the set the status bar color for iOS.

    XAML usage:

    In order to make use of the toolkit within XAML you can use this namespace:

    xmlns:toolkit="http://schemas.microsoft.com/dotnet/2022/maui/toolkit"
    

    And then add below to your XAML page:

     <ContentPage.Behaviors> 
            <toolkit:StatusBarBehavior StatusBarColor="Red" StatusBarStyle="LightContent"> 
            </toolkit:StatusBarBehavior>
     </ContentPage.Behaviors>