Adding a custom font to macOS app using Swift

前端 未结 5 2032
梦谈多话
梦谈多话 2021-02-20 10:46

I followed a bunch of tutorials but it doesn’t work: I simply want to add a custom font to a macOS app.

What I tried essentially:

  1. Added the .
5条回答
  •  北恋
    北恋 (楼主)
    2021-02-20 11:42

    I solved my problem by accident.

    I noticed that within the Bundle files, my fonts were included twice: They were copied to the "Resources" directory as well as to the subpath I declared in the "Copy Files" Build Phases. I removed the fonts from my project, added them again (without checking the "Target Membership") and added them in the Build Phases so they were copied just to the subpath. After that it worked.

    Additional notes:

    Turned out that Fonts provided by application is a iOS only property so it is not needed for an macOS implementation.

    Also, ATSApplicationFontsPath does not need any slashes. For example: Fonts should work just fine.

    I had a difficult time finding the correct names for .ttf font files and sometimes discovered some strange behaviour: NSFont picked randomly fonts (regular, medium, bold...) from a font family without any code changes. By using .otf files instead I could solve that too.

提交回复
热议问题