Custom Font in Forms Labs ExtendedLabel

I'm trying to use ExtendedLabel to set a custom font in code, but all I get is the default System Font. Here's what I have, pretty straightforward:

        `var myLabel = new ExtendedLabel
        {
            Text = "some text",
            FontSize = 60, 
            HorizontalOptions = LayoutOptions.StartAndExpand,
            VerticalOptions = LayoutOptions.Center,
            TextColor = Color.Pink,
            FontName = "OpenSans.ttf"
        };`

I've tried putting the font file (OpenSans.ttf) in my Android project under /Assets and /Assets/fonts. I've tried referencing it with no path, as well as both of those paths. The font file build action property is set to Android Asset. Also, the FontSize property doesn't seem to work on Windows Phone. Is there anything else I should try?

Posts

  • rogiheerogihee NLMember ✭✭✭
    edited November 2014

    Don't know exactly if that is the case with Android as well, but on iOS the font family name may be different from the filename.

  • Yeah I've tried including/omitting the file extension, substituting font family name/font file name, using different fonts etc. Has anyone gotten custom fonts working for Android in Forms via code (not xaml)?

  • Also, this isn't explicitly a ExtendedLabel Labs question. Custom fonts don't show in regular Labels for vanilla Forms.

  • KamilKuza.8560KamilKuza.8560 USMember, University

    Yes. The below worked for me:

    (1) Make sure Font-Name is the filename.
    (2) Make sure FriendlyFontName matches "Font Name" line in windows font viewer. See screenshot.
    (3) Font must be in \Assets\fonts. Lower case required
    (4) Build action of file set to "AndriodAsset"

Sign In or Register to comment.