Modal Page Presentation Style on iOS

Download Sample Download the sample

This iOS platform-specific is used to set the presentation style of a modal page. It's consumed in XAML by setting the Page.ModalPresentationStyle bindable property to a UIModalPresentationStyle enumeration value:

<ContentPage ...
             xmlns:ios="clr-namespace:Xamarin.Forms.PlatformConfiguration.iOSSpecific;assembly=Xamarin.Forms.Core"
             ios:Page.ModalPresentationStyle="FormSheet">
    ...
</ContentPage>

Alternatively, it can be consumed from C# using the fluent API:

using Xamarin.Forms.PlatformConfiguration;
using Xamarin.Forms.PlatformConfiguration.iOSSpecific;
...

public class iOSModalFormSheetPageCS : ContentPage
{
    public iOSModalFormSheetPageCS()
    {
        On<iOS>().SetModalPresentationStyle(UIModalPresentationStyle.FormSheet);
        ...
    }
}

The Page.On<iOS> method specifies that this platform-specific will only run on iOS. The Page.SetModalPresentationStyle method, in the Xamarin.Forms.PlatformConfiguration.iOSSpecific namespace, is used to set the modal presentation style on a Page by specifying one of the following UIModalPresentationStyle enumeration values:

  • FullScreen, which sets the modal presentation style to encompass the whole screen. By default, modal pages are displayed using this presentation style.
  • FormSheet, which sets the modal presentation style to be centered on and smaller than the screen.

In addition, the GetModalPresentationStyle method can be used to retrieve the current value of the UIModalPresentationStyle enumeration that's applied to the Page.

The result is that the modal presentation style on a Page can be set:

Note

Pages that use this platform-specific to set the modal presentation style must use modal navigation. For more information, see Xamarin.Forms Modal Pages.