3

I am working with custom fonts right now and currently a font named: "Yellowtail-Regular.tff". I created a map called Fonts in my iOS folder and I added the tff file in there. After that I went to my Info.plist and created a Fonts provided by application and in there I created a new string called Fonts/Yellowtail-Regular.ttf.

When I now try to use it like this:

<Label FontFamily = "Yellowtail" Text = "Testing my label" />

The standard font (Helvetica Neue) still remains. I also tried with:

<Label FontFamily = "Yellowtail-Regular" Text = "Testing my label" />

But with the same outcome.

Am I missing a step or am I doing something wrong?

6
  • developer.xamarin.com/recipes/ios/standard_controls/labels/… Commented Jan 10, 2017 at 11:00
  • I did not find Yellowtail-Regular in ios fonts, developer.xamarin.com/recipes/ios/standard_controls/fonts/… Commented Jan 10, 2017 at 11:02
  • Ah ok so if it isnt in the ios-fonts there is no way of adding it? Commented Jan 10, 2017 at 11:02
  • Try alter your file fonts for "Always copy" Commented Jan 10, 2017 at 11:04
  • Where do I find this? If i right click on the font I see build action, quick properties etc, is that option in there somewhere? Commented Jan 10, 2017 at 11:05

2 Answers 2

7

If you are using Yellowtail-Regular.ttf from http://www.1001freefonts.com/yellowtail.font, then that font name under iOS would be just Yellowtail.

Each platform has different naming conventions, so using Device.OnPlatform might look something like:

public Label()
{
  FontFamily = Device.OnPlatform("Yellowtail", "Yellowtail-Regular", "/Assets/Yellowtail-Regular.ttf#Yellowtail-Regular");      
}

To confirm your iOS font family name, on macOS open your .ttf using Font Book and the name that macOS/iOS will use is the one in the title bar of the app.

Sign up to request clarification or add additional context in comments.

1 Comment

Solid advice, the opening the font with Font Book. I couldn't figure out the name! :P
7

Some times font book will display the name with spaces.

In my case: Font name is : SFProDisplay-Ultralight. But the font book shown the name as "SF Pro Display Ultralight". Due to this custom font is not working in iOS.

So you can use the below code to find the correct font name and apply it in the iOS. Add this code in the AppDelegate launch method. Then you can find the list of viable font names in the Application output.

foreach (var family in UIFont.FamilyNames)
{
    System.Diagnostics.Debug.WriteLine($"{family}");

    foreach (var names in UIFont.FontNamesForFamilyName(family))
    {
        System.Diagnostics.Debug.WriteLine($"{names}");
    }
}

After that you can use xaml to refer the font.

<OnPlatform x:Key="SFProDisplayUltraLight" x:TypeArguments="x:String">
    <On Platform="iOS" Value="SFProDisplay-Ultralight" />
    <On Platform="Android" Value="SF-Pro-Display-Ultralight.otf#SF Pro Display Ultralight" />
</OnPlatform>

Then Apply it for the control.

<Lable Text="Welcome" FontFamily="{StaticResource SFProDisplayUltraLight}"/>

1 Comment

This should be in the documentation. All the documentation I've read is vague or only has the name of a single font and only this correctly describes how to get the correct font names.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.