.net maui onplatform 字体大小不适用于 iOS

问题描述 投票:0回答:1

我正在尝试使用 OnPlatform XAML 选项来获取适合不同平台的适当字体大小。下面的代码片段,值只是示例;我尝试过很多不同的!

Android 和 UWP 会响应我设置的任何内容,但对于 iOS 来说,什么都不会改变。 (顺便说一句,我也无法更改 iOS 上的字体颜色,但目前我对此不太担心!)

有人有什么提示吗?

<RadioButton Style="{StaticResource RBStyle}" Content="Cy" VerticalOptions="Center" >
  <RadioButton.FontSize>
      <OnPlatform x:TypeArguments="x:Double">
          <On Platform="Android" Value="20"/>
          <On Platform="iOS" Value="10"/>
          <On Platform="UWP" Value="30"/>
      </OnPlatform>
  </RadioButton.FontSize>
</RadioButton>
ios maui font-size
1个回答
1
投票

这似乎是 .NET MAUI 中的一个错误。

FontAttributes
属性在 iOS 上也不起作用。

幸运的是,iOS 支持使用

View
作为
Content
RadioButton
属性,因此您可以应用这样的解决方法。

MainPage.xaml

<RadioButton Content="Cy" VerticalOptions="Center" x:Name="MyRadioButton">
    <RadioButton.FontSize>
        <OnPlatform x:TypeArguments="x:Double">
            <On Platform="Android" Value="20"/>
            <On Platform="UWP" Value="30"/>
        </OnPlatform>
    </RadioButton.FontSize>
</RadioButton>

MainPage.xaml.cs

public MainPage()
{
    InitializeComponent();
    
#if IOS
    MyRadioButton.Content = new Label
    {
        Text = "Cy",
        FontSize = 10
    };
#endif
}

如果您想跟踪问题状态:https://github.com/dotnet/maui/issues/19081

© www.soinside.com 2019 - 2024. All rights reserved.