在mac包中嵌入字体 [英] Embed font in a mac bundle
问题描述
我有一个我写的程序。我想使用一种花哨的字体。我可以只是嵌入我的字体到我的捆绑,并使用它从那里。
I have a program I am writing. I want to use a fancy font. Can I just embed my font into my bundle and use it from there.
我的代码...
NSMutableAttributedString *recOf;
recOf = [[NSMutableAttributedString alloc] initWithString:@"In Recognition of"];
length = [recOf length];
[recOf addAttribute:NSFontAttributeName value:[NSFont fontWithName:@"Edwardian Script ITC" size:50] range:NSMakeRange(0, length)];
[[NSColor blackColor] set];
p.x = (bounds.size.width/2)- (([recOf size].width)/2);
p.y = (bounds.size.height/1.7);
[recOf drawAtPoint:p];
[recOf release];
推荐答案
您应该向目标中添加复制文件构建阶段(右键单击目标,然后选择添加>新构建阶段>新建拷贝文件构建阶段)。
Yes, you can. You should add a Copy Files
build phase to your target (right-click your target, then choose Add > New Build Phase > New Copy Files Build Phase).
将复制文件构建阶段的目标设置为资源,路径为字体
。这将确保字体被复制到您的应用程序包中的 Fonts
文件夹中。
Set the destination of the Copy Files build phase to Resources with a path of Fonts
. This will make sure the font is copied into a folder named Fonts
in your application bundle.
添加您的字体文件
然后,您需要添加 ATSApplicationFontsPath
键到您的 Info.plist
文件,其中包含您的字体的文件夹的名称为其值:
You then need to add the ATSApplicationFontsPath
key to your Info.plist
file, with the name of the folder containing your font as its value:
<key>ATSApplicationFontsPath</key>
<string>Fonts</string>
然后,您可以使用应用程序中的字体,就像它是一个内置的系统字体。 [NSFont fontWithName:@yourFontName]
。
You can then use the font in your app as if it were a built-in system font by calling [NSFont fontWithName:@"yourFontName"]
.
当然,您应该确保您有权限在这之前分配字体。
Of course, you should make sure that you have permission to distribute the font before doing this.
这篇关于在mac包中嵌入字体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!