此项平台特定功能可控制是否调整 NavigationPage 上的状态栏文本颜色以匹配导航栏的亮度。 其使用方式为,在 XAML 中将 NavigationPage.StatusBarTextColorMode 附加属性设置为 StatusBarTextColorMode 枚举的值:
<FlyoutPage xmlns="http://xamarin.com/schemas/2014/forms"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
    xmlns:ios="clr-namespace:Xamarin.Forms.PlatformConfiguration.iOSSpecific;assembly=Xamarin.Forms.Core"
    x:Class="PlatformSpecifics.iOSStatusBarTextColorModePage">
    <FlyoutPage.Flyout>
        <ContentPage Title="Flyout Page Title" />
    </FlyoutPage.Flyout>
    <FlyoutPage.Detail>
        <NavigationPage BarBackgroundColor="Blue" BarTextColor="White"
                        ios:NavigationPage.StatusBarTextColorMode="MatchNavigationBarTextLuminosity">
            <x:Arguments>
                <ContentPage>
                    <Label Text="Slide the master page to see the status bar text color mode change." />
                </ContentPage>
            </x:Arguments>
        </NavigationPage>
    </FlyoutPage.Detail>
</FlyoutPage>
或者,可以使用 Fluent API 从 C# 使用它:
using Xamarin.Forms.PlatformConfiguration;
using Xamarin.Forms.PlatformConfiguration.iOSSpecific;
...
IsPresentedChanged += (sender, e) =>
{
    var flyoutPage = sender as FlyoutPage;
    if (flyoutPage.IsPresented)
        ((Xamarin.Forms.NavigationPage)flyoutPage.Detail)
          .On<iOS>()
          .SetStatusBarTextColorMode(StatusBarTextColorMode.DoNotAdjust);
    else
        ((Xamarin.Forms.NavigationPage)flyoutPage.Detail)
          .On<iOS>()
          .SetStatusBarTextColorMode(StatusBarTextColorMode.MatchNavigationBarTextLuminosity);
};
该 NavigationPage.On<iOS> 方法指定此平台特定仅在 iOS 上运行。 该方法 NavigationPage.SetStatusBarTextColorMode 在 Xamarin.Forms.PlatformConfiguration.iOSSpecific 命名空间中可控制是否调整 NavigationPage 上状态栏文本颜色以匹配导航栏的亮度,其中 StatusBarTextColorMode 枚举会提供两个可能的值:
- DoNotAdjust- 指示不应调整状态栏文本颜色。
- MatchNavigationBarTextLuminosity- 指示状态栏文本颜色应与导航栏的亮度相匹配。
此外,GetStatusBarTextColorMode 方法还可用于检索应用于 NavigationPage 的 StatusBarTextColorMode 枚举当前值。
结果是可以调整 NavigationPage 上的状态栏文本颜色以匹配导航栏的亮度。 在此示例中,当用户在以下页面 FlyoutPage 的 Flyout 和 Detail 页面之间切换时,状态栏文本颜色会发生变化:
