1
votes

I tried to use custom font in Xamarin iOS using this guide. I added the fonts to Resources/Fonts folder. And then added it to the info.plist under the array property Fonts provided by application. I changed the property of font to Bundle Resource and Copy Always.

Now, the newly added font have to be shown in xamarin designer. But, it is not showing for Roboto-Regular.ttf. But It is working fine for OpenSans-Regular.ttf.

Any help are welcome!

1
I have similar issues with the xamarin designer, I have to open the files with xml editor set the font name manually and reload the ui designer... driving me crazyCyprien Autexier

1 Answers

0
votes

iOS may register the font under different font name. If your font was successfully registered (as your steps indicate you did), you can find it inside UIFonts.FontFamilyNames array and then use that. To find all registered fonts,

foreach (var fontFamily in UIFont.FamilyNames)
{
    foreach (var font in UIFont.FontNamesForFamilyName(font))
    {
        System.Diagnostics.Debug.Console.WriteLine(item);
    }
    System.Diagnostics.Debug.Console.WriteLine("---");
}

if you still don't see your font. Try to find it explicitly by name,

foreach (var font in UIFont.FontNamesForFamilyName(friendlyFontName)) // can have space in font name.
{
    System.Diagnostics.Debug.Console.WriteLine(item);
}
System.Diagnostics.Debug.Console.WriteLine("---");

If you find your font there, that's what you need to use as font name in your code.

Example,

I recently used Bbas Neue. The file names where,

  • BebasNeue Regular.ttf
  • BebasNeue Bold.ttf
  • BebasNeue Thin.ttf

In android, I used BebasNeue Regular.ttf#BebasNeue Regular and it worked as expected. In iOS, however, the font names were as follows,

  • BebasNeueRegular
  • BebasNeueBold
  • BebasNeue-Thin

as you can see, not in any pattern. So after looking for font family Bebas Neue (with the space), I found the correct names, and was able to use the font on iOS.

Hope this helps.