Setting Label.FontFamily from code does not work on iOS?

ZoliZoli NLMember ✭✭✭
edited March 19 in Xamarin.Forms

Hi,

I did setup everything to use custom fonts in Xamarin.Forms.
I use it from XAML, all works fine, both Android + iOS.

<Label FontSize="Large"        TextColor="Black"        HorizontalOptions="Center"   Text="{Binding TextSound}">
    <Label.FontFamily>
        <OnPlatform x:TypeArguments="x:String" Android="wot_turbo.ttf#wot_turbo" iOS="wot_turbo"/>
    </Label.FontFamily>
</Label>

However, if I use it from the View C# code, it ONLY works fine on Android.
On iOS, I see "?" instead of the proper letter.

new Label
{
    FontSize = Device.GetNamedSize(NamedSize.Large, typeof(Label)),
    FontAttributes = FontAttributes.Bold,
    TextColor = Color.Black,
    FontFamily = Device.RuntimePlatform == Device.iOS ? "wot_turbo" : "wot_turbo.ttf#wot_turbo",
    Text = Const.FONT_ICON.YES
}

Any idea what might be the issue?
Thx

Tagged:

Best Answer

  • ZoliZoli NL ✭✭✭
    Accepted Answer

    Ok...the reason is FontAttributes = FontAttributes.Bold is only used in the C#, not in XAML. It seems the Font does not contain(?) bold version of letters?
    Strange it works in Android...

Answers

  • ZoliZoli NLMember ✭✭✭
    Accepted Answer

    Ok...the reason is FontAttributes = FontAttributes.Bold is only used in the C#, not in XAML. It seems the Font does not contain(?) bold version of letters?
    Strange it works in Android...

Sign In or Register to comment.