How to use custom fonts in a mac application?

前端 未结 6 1414
天涯浪人
天涯浪人 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:03

    ATSApplicationFontsPath is for macOS:

    ATSApplicationFontsPath (String - macOS) identifies the location of a font file or directory of fonts in the bundle’s Resources directory. If present, macOS activates the fonts at the specified path for use by the bundled app. The fonts are activated only for the bundled app and not for the system as a whole. The path itself should be specified as a relative directory of the bundle’s Resources directory. For example, if a directory of fonts was at the path /Applications/MyApp.app/Contents/Resources/Stuff/MyFonts/, you should specify the string Stuff/MyFonts/ for the value of this key.

    macOS app Instructions:

    1. Select your Xcode project in the project navigator
    2. Select your app target
    3. Click the + button and to add a New Copy Files Phase
    4. Select Resources for the destination
    5. Under subpath specify the directory (e.g. Fonts) where your embedded fonts will be copied to within your application bundle's Resources directory.
    6. Drag and drop the font files into the file list of the Copy Files build phase.

    UIAppFonts is for iOS:

    UIAppFonts (Array - iOS) Specifies any app-provided fonts that should be made available through the normal mechanisms. Each item in the array is a string containing the name of a font file (including filename extension) that is located in the app’s bundle. The system loads the specified fonts and makes them available for use by the app when that app is run.

    This key is supported in iOS 3.2 and later.

提交回复
热议问题