iosmauifont-size

.net maui onplatform font size not working for iOS


I'm trying to use OnPlatform XAML option to get appropriate font sizes for different platforms. Code snippet below, values just samples; I've tried many different ones!

Android and UWP respond to whatever I set, but for iOS nothing ever changes. (And just as an aside, I can't change the font color on iOS either, but I'm less worried about that at the moment!)

Any hints anyone?

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

Solution

  • This seems to be a bug in .NET MAUI.

    FontAttributes property doesn't work on iOS, too.

    Fortunately, iOS supports using a View for the Content property of RadioButton, so you can apply a workaround like this.

    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
    }
    

    If you want to track the issue status: https://github.com/dotnet/maui/issues/19081