Ios Xamarin forms-将所有页面的SetUseSafeArea全局设置为true
在xamarin形式中,您可以使用Ios Xamarin forms-将所有页面的SetUseSafeArea全局设置为true,ios,xamarin.forms,Ios,Xamarin.forms,在xamarin形式中,您可以使用 On().setUseSaferage(true) 这将确保您的视图不会显示在任何凹口/不安全区域上 我想知道是否有任何方法可以全局设置,这样我就不必在每个内容页中不断添加那行代码 首选不带自定义渲染器的解决方案(除非这是唯一可以实现的方法)将其添加到应用程序中。参考资料 <Application xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://s
On().setUseSaferage(true)代码>
这将确保您的视图不会显示在任何凹口/不安全区域上
我想知道是否有任何方法可以全局设置,这样我就不必在每个内容页中不断添加那行代码
首选不带自定义渲染器的解决方案(除非这是唯一可以实现的方法)将其添加到应用程序中。参考资料
<Application
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:iOsSpecific="clr-namespace:Xamarin.Forms.PlatformConfiguration.iOSSpecific;assembly=Xamarin.Forms.Core"
x:Class="YourApp.App">
<Application.Resources>
<ResourceDictionary>
<Style TargetType="iOsSpecific:Page">
<Setter Property="UseSafeArea" Value="True"/>
</Style>
它将针对特定于iOS平台的全局所有页面。唯一的方法是在页面的自定义呈现程序中启用安全区域
[assembly: ExportRenderer(typeof(Xamarin.Forms.Page), typeof(MyRenderer))]
namespace App1.iOS
{
class MyRenderer :PageRenderer
{
protected override void OnElementChanged(VisualElementChangedEventArgs e)
{
base.OnElementChanged(e);
var page = Element as Xamarin.Forms.Page;
page.On<Xamarin.Forms.PlatformConfiguration.iOS>().SetUseSafeArea(true);
}
}
}
[程序集:ExportRenderer(typeof(Xamarin.Forms.Page)、typeof(MyRenderer))]
名称空间App1.iOS
{
类MyRenderer:PageRenderer
{
受保护的覆盖无效OnElementChanged(VisualElementChangedEventArgs e)
{
基础。一个要素发生变化(e);
var page=元素为Xamarin.Forms.page;
page.On().setUseSaferage(true);
}
}
}
在我的应用程序中,这适用于我。xaml:
<Style TargetType="ContentPage" ApplyToDerivedTypes="True">
<Setter Property="BackgroundColor" Value="White" />
<Setter Property="iOsSpecific:Page.UseSafeArea" Value="True"/>
</Style>
我试过了,不幸的是这对我不起作用。
xmlns:iOsSpecific="clr-namespace:Xamarin.Forms.PlatformConfiguration.iOSSpecific;assembly=Xamarin.Forms.Core"