The article is just an extension of my article "Using Custom Fonts In Xamarin.Forms". So, before you proceed with this blog, please go through my previous article.
In this write-up, I will explain you how to add custom fonts for Xamarin.Forms iOS app.
Step 1
After creating XAML file, add your (custom font) .ttf files in Resources folder of iOS project, as shown in the above screenshot. In my project, my custom font file is "Pacifico.ttf".
Step 2
Open the properties of (custom font).ttf file by right clicking on the file and changng the "Copy to Output Directory" option to "Copy always".
Step 3
Open the info.plist file of iOS project in XAML (text) editor view, and copy the following code in it.
- <key>UIAppFonts</key>
-
- <array>
-
- <string>(your custom font file).ttf</string>
-
- </array>
As shown in the above screenshot.
step 4
Open your .xaml file and copy the following code in it.
- <ContentPage.Resources>
- <ResourceDictionary>
- <Style x:Key="BaseLabelStyle" TargetType="Label">
- <Setter Property="TextColor" Value="Black"/><Setter Property="FontSize" Value="25"/>
- </Style>
- <Style x:Key="PacificoLabelStyle" TargetType="Label" BaseResourceKey="BaseLabelStyle">
- <Setter Property="FontFamily"><Setter.Value><OnPlatform x:TypeArguments="x:String" iOS="Pacifico" Android="Pacifico.ttf#Pacifico"/></Setter.Value></Setter>
- </Style>
- </ResourceDictionary>
- </ContentPage.Resources>
- <StackLayout>
- <Label Text="Default" Style="{StaticResource BaseLabelStyle}"></Label>
- <Label Text="Default" Style="{StaticResource PacificoLabelStyle}"></Label>
- </StackLayout>
Step 5
Finally, when you run the project in your iOS Simulator, the following output appears.