Using Custom Font Family in Xamarin Forms
Ever wondered how to use a custom font family for your App Label, Button, Entry, etc? In this article, we will learn how to use a cool custom font family & make our App UI more attractive & cool. I will be using Google Fonts for this article.
Let’s divide the process into 4 steps given below
- Choose your favorite google font from here and download the font zip.
- Add the font .tff file to respective platform folders
- Finally, the code to make the magic work.
1. Download Google Font
You can choose any font family from the Awesome Google Font library and download the family.
2. Add Font Family
Now let’s add the downloaded font family into our platform-specific folders for Android & iOS.
Android → Add the .tff file into the Assets folder of the Android Project & make sure the Build Action of those files are set to AndroidAsset. Right-click on the font-family file & select Properties to view the Build Action.
iOS → Add the .tff file into the Resources folder of the iOS Project & make sure the Build Action of those files are set to BundleResource. Right-click on the font-family file & select Properties to view the Build Action.
3. Let’s Code
We will be creating a ContentPage that will have a Label & 2 Buttons to switch from one font family to other.
Font Resource File
Let’s create a separate static class that will have the font family definition defined.
CustomFontPage Xaml Code
CustomFontPage Code Behind
That’s it our custom font family implementations are done. Do let me know what other topics should I cover next.