How to use custom fonts in a mac application?

前端 未结 6 1433
天涯浪人
天涯浪人 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条回答
  •  没有蜡笔的小新
    2020-12-16 19:20

    For those whose font family is called something like My-Custom-Font-Family: be aware that in code you should instantiate your custom font like this: NSFont(name: "MyCustomFontFamily-Bold", size: 20) Spaces and "-" are ignored and font type is written after "-". I did not see this in any docs and spend a few hours trying to figure out wtf was wrong. Also if you want to get list of all available fonts you can use this code

    for font in NSFontManager.shared.availableFonts {
        print(font)
    }
    

提交回复
热议问题