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>
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>
Finally, when you run the project in your iOS Simulator, the following output appears.
No comments:
Post a Comment