#Xamarin Forms: What is the Font Name in iOS for a Style?

download.pngIn Xamarin Forms you can use your own fonts, but there is a trick. In iOS you need to know the name of the font, which may not be obvious.

In this Style example, you can see that I am referencing the FontAwesome Solid font. Notice the dash and how different it is in Android.

<OnPlatform x:Key="FontAwesomeSolidFontFamily" x:TypeArguments="x:String"
            Android="fa-solid-900.ttf#Font Awesome 5 Pro Solid"
            iOS="FontAwesome5Pro-Solid" />

To get the name needed for iOS, which is different from Android, use this bit of code in your iOS AppDelegate.cs (Don’t forget to remove it when done)

foreach (var familyNames in UIFont.FamilyNames.OrderBy(c => c).ToList())
    Console.WriteLine(" * " + familyNames);
    foreach (var familyName in UIFont
           .OrderBy(c => c).ToList())
        Console.WriteLine(" *-- " + familyName);

When run, open the Output window and you’ll see all the names off the fonts on the device and those you added in your info.plist.

Here’s my info.plist for FontAwesome Solid.

		<string>Font Awesome 5 Pro-Light-300.otf</string>
		<string>Font Awesome 5 Pro-Solid-900.otf</string>


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s