NavigationPage Bar Textfarbmodus unter iOS

Beispiel herunterladen Das Beispiel herunterladen

Mit dieser plattformspezifischen Steuerung wird gesteuert, ob die status Textfarbe des Balkens an NavigationPage die Leuchtkraft der Navigationsleiste angepasst wird. Es wird in XAML verwendet, indem die NavigationPage.StatusBarTextColorMode angefügte Eigenschaft auf einen Wert der StatusBarTextColorMode Enumeration festgelegt wird:

<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>

Alternativ kann sie über C# mit der Fluent-API genutzt werden:

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);
};

Die NavigationPage.On<iOS> -Methode gibt an, dass diese plattformspezifische Nur unter iOS ausgeführt wird. Die NavigationPage.SetStatusBarTextColorMode -Methode steuert im Xamarin.Forms.PlatformConfiguration.iOSSpecific Namespace, ob die status Textfarbe des NavigationPage Balkens an die Helligkeit der Navigationsleiste angepasst wird, wobei die StatusBarTextColorMode Enumeration zwei mögliche Werte bereitstellt:

  • DoNotAdjust– gibt an, dass die status Textfarbe des Balkens nicht angepasst werden soll.
  • MatchNavigationBarTextLuminosity– gibt an, dass die status Textfarbe der Leuchtkraft der Navigationsleiste entsprechen soll.

Darüber hinaus kann die GetStatusBarTextColorMode -Methode verwendet werden, um den aktuellen Wert der Enumeration abzurufen, die StatusBarTextColorMode auf NavigationPageangewendet wird.

Das Ergebnis ist, dass die status Textfarbe des Balkens an NavigationPage die Leuchtkraft der Navigationsleiste angepasst werden kann. In diesem Beispiel ändert sich die status Textfarbe des Balkens, wenn der Benutzer zwischen den Flyout Seiten und Detail eines FlyoutPagewechselt:

Statusleiste Textfarbmodus plattformspezifisch