0
votes

I'm using a custom font in our app, and have found that if I set a FontAttributes="Bold" for a Label style using the font, it works on the iOS simulator, but not on a real device.

Steps taken: 1. Added the font Effra_Std_Reg.ttf to the resources folder. 2. Added this to the Fonts Provided By The Application element in Info.plist and set its build actions. 3. Created Styles in App.XAML. 4. Added these styles to the XAML on my page.

All the above works fine for a Label with no FontAttributes set. As soon as I set FontAttributes="Bold" on either the Style or the Label itself, the system font is used insted. Note that this works on the Simulator.

I know that the FontFamily is the font Name as defined inside the ttf file - not the ttf filename.

This on an iPad running iOS 10.3.3.

My App.XAML is:

<?xml version="1.0" encoding="utf-8" ?>
<Application x:Class="FontTest.App"
             xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml">
    <Application.Resources>
        <ResourceDictionary>
            <Style TargetType="Label">
                <Setter Property="FontSize" Value="30" />
            </Style>

            <Style x:Key="PlainLabelStyle" TargetType="Label">
                <Setter Property="FontFamily">
                    <Setter.Value>
                        <OnPlatform x:TypeArguments="x:String"
                                    Android="Effra_Std_Rg.ttf#Effra"
                                    iOS="Effra" />
                    </Setter.Value>
                </Setter>
            </Style>

            <Style x:Key="BoldLabelStyle" TargetType="Label">
                <Setter Property="FontFamily">
                    <Setter.Value>
                        <OnPlatform x:TypeArguments="x:String"
                                    Android="Effra_Std_Bd.ttf#Effra"
                                    iOS="Effra" />
                    </Setter.Value>
                </Setter>
               <Setter Property="FontAttributes" Value="Bold" />
            </Style>

        </ResourceDictionary>
    </Application.Resources>
</Application>

And my page XAML (extract) is:

 <Label Grid.Row="4"
               Grid.Column="1"
               Style="{StaticResource BoldLabelStyle}"
               Text="QWERTYUIOPASDFGHJKLZXCVBNM" />
1

1 Answers

0
votes

To get it working on the device, I had to include the bold font file (Effra_Std_Bd.ttf), and specify a FontFamily of 'Effra-Bold'.

So it appears that the FontFamily needs to be the Name and the Style.

Strange that it worked on the Simulator.