How to install custom font in mac programmatically in macOS

你离开我真会死。 提交于 2020-03-24 21:24:11

问题


I am having a mac app in which I have custom font which is not there in my custom font book of application folder in my mac.

So, when an app launches, I checked it that if a font is installed in mac or not with the below code.

NSArray *fonts = [[NSFontManager sharedFontManager] availableFontFamilies];

if ([fonts containsObject:@"Square721 BT"])
{
    NSLog(@"Fonts Available");
}
else
{
    NSLog(@"No fonts");
}

Now, if the font is not already installed, how can I install it programmatically?


回答1:


  1. Add your font ttf file to your application bundle, e.g. in Contents/Resources/Fonts/
  2. In your info.plist add the key: ATSApplicationFontsPath and string: Fonts

See: https://developer.apple.com/library/mac/documentation/General/Reference/InfoPlistKeyReference/Articles/GeneralPurposeKeys.html#//apple_ref/doc/uid/TP40009253-SW8

And here's a relevant Stack Overflow answer: https://stackoverflow.com/a/29003792/3342547



来源:https://stackoverflow.com/questions/31200618/how-to-install-custom-font-in-mac-programmatically-in-macos

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!