Custom Fonts only available when set in Interface Builder

前端 未结 6 1155
暖寄归人
暖寄归人 2021-01-13 08:50

I have added a custom font to my project. It is included in the target, and it is added in the plist. When I try to use it programmatically it doesn\'t work, and it doesn\'t

6条回答
  •  忘掉有多难
    2021-01-13 09:32

    Ok, topic is old but I would like to put in my two cents here.

    First off all, read this article http://codewithchris.com/common-mistakes-with-adding-custom-fonts-to-your-ios-app/

    In brief:

    1. remember to include your fonts to project
    2. setup target for fonts
    3. check if your fonts are included as resources in bundle
    4. add custom fonts to plist file
    5. check the real name of your font in code

    When I did everything like described in this article, my fonts works in interface builder only. I also have problem with step 5 - my fonts did not show up in console output.

    Ok, so now is time for tips from me:

    TIP #1

    use otf font format, if you have different, convert it (or ask your designer ;) ) you can use this site for that: https://onlinefontconverter.com/

    TIP #2

    In article above you can find:

    Open it and add a new row called “Fonts provided by application” which will be an array that you need to add all the filenames of the fonts you want to use.

    Instead of "Fonts provided by application" enter "UIAppFonts" Remember, if you have more than one plist file, set this for all.

提交回复
热议问题