Alan2
Alan2

Reputation: 24562

I can't get my custom fonts to work with Xamarin.Forms

I created this resource:

<?xml version="1.0" encoding="utf-8"?> <Application xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="CustomFrameApp.App">
    <Application.Resources>
        <ResourceDictionary>
            <OnPlatform x:TypeArguments="x:String" x:Key="NewFont">
                <On Platform="iOS" Value="Camber_Medium_Regular" />
            </OnPlatform>
        </ResourceDictionary>
    </Application.Resources> </Application>

added to info.plist

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>UIAppFonts</key>
    <array>
        <string>Camber_Medium_Regular.otf</string>
    </array>
</dict>
</plist>

and used in my XAML

<Label FontSize="12px" Text="ABCD" TextColor="Black" VerticalOptions="Center" HorizontalOptions="Center" FontFamily="{StaticResource NewFont}" />

But the fonts are still not being used

I added them as bundle resource as suggested and they are in the resource file of iOS

Does anyone have any idea what might be wrong?

Upvotes: 0

Views: 157

Answers (1)

Cherry Bu - MSFT
Cherry Bu - MSFT

Reputation: 10346

According to Fonts in Xamarin.Forms, please confirm three things:

  1. If you have added font file tat called Camber_Medium_Regular.ttf in Resource file , and Build Action:BundleResource

2.Update the Info.plist, like this:

    <key>UIAppFonts</key>
<array>
    <string>Camber_Medium_Regular.ttf</string>
</array>

3.Refer to it by name

<OnPlatform x:TypeArguments="x:String">
                <On Platform="iOS" Value="Camber_Medium_Regular" />
                <On Platform="Android" Value="Lobster-Regular.ttf#Lobster-Regular" />
                <On Platform="UWP" Value="Assets/Fonts/Lobster-Regular.ttf#Lobster" />
            </OnPlatform>

Upvotes: 1

Related Questions