locked
Bold custom font on iOS works on simulator but not on device RRS feed

  • Question

  • User350 posted

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

    Edit I'm aware of the fact that the FontFamily needs to refer to the font's name as defined inside the ttf file, not the ttf filename itself.

    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" />
    
    Sunday, August 13, 2017 9:14 AM

Answers

  • User350 posted

    To get it working on the device, I had to include the bold font file (EffraStdBd.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.

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Sunday, August 13, 2017 10:14 AM

All replies

  • User350 posted

    To get it working on the device, I had to include the bold font file (EffraStdBd.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.

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Sunday, August 13, 2017 10:14 AM
  • User75709 posted

    @JamesLavery : This is still the case unfortunately, so there is no easy way to do handle bold font with just regular custom font ?

    Thursday, September 12, 2019 1:47 PM