How do you integrate custom fonts in an app?

前端 未结 2 1917
南笙
南笙 2020-12-11 07:24

I am trying to integrate custom fonts (Imperator.ttf and goodfish.ttf) from the following website into my corona app:
http://www.1001freefonts.com/top-fonts.php

相关标签:
2条回答
  • 2020-12-11 07:59

    Put Imperator.ttf font file in Assets folder

    In class use following code:

    Typeface imperator_typeface =Typeface.createFromAsset(getContext().getAssets(),"Imperator.ttf");

    your_textview.setTypeface(imperator_typeface);

    0 讨论(0)
  • 2020-12-11 08:06

    While installing custom fonts to your corona application, you have to follow the following steps:

    • Install the font in your system.
    • Copy and paste the font file(such as: Imperator.ttf) to the application folder where your main.lua exists.
    • Then for iPhone(only for iPhone, Android doesn't need this), add the following lines to your build.settings:

    iphone =
        {
            plist =
            {
                UIAppFonts =
                {
                    "Imperator.ttf"  -- Font file name
                },
                UIApplicationExitsOnSuspend = true
            },
        }
    

    • Debug and get the supported Font Names by the system using the following:

    local fonts = native.getFontNames()
    for i,fontname in ipairs(fonts) do
        print(fonts[i])
    end
    

    From the above debugging, you can get the exact Font Name (here: Imperator) that you have to use while creating the text/label. Sometimes this may differ from the name of the font file. You can also get it from applications like photoshop(it's text tool font name), etc.

    local myText = display.newText("Label with custom font",150,100,"Imperator",20)
    

    Then finally, you will get the output as:

    enter image description here

    Keep coding................

    0 讨论(0)
提交回复
热议问题