How to use custom fonts in a mac application?

前端 未结 6 1426
天涯浪人
天涯浪人 2020-12-16 18:35

I try to use custom fonts in my swift app, but they don\'t load.

I copy the fonts.ttf in my resources folder, and I added the names in Info.plist under \"Fonts pro

6条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-16 19:12

    As "Application fonts resource path" is now a string type in XCode 7.3.1 and I couldn't seem to find a way to use an Array for multiple fonts, I used "." in the Info.plist:

         Application fonts resource path     String    .
    

    and this seemed to work to pick up all my custom fonts in a Resources folder dynamically e.g. using Swift

     labelText.font = NSFont(name: "DS-Digital", size: 48)
    

    However, to see it in XCode design mode (to choose a font from drop-down menu), I needed to first add the font to Font Book.

    However, Font Book was not required for the dynamic method to work :)

提交回复
热议问题