在 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];
推荐答案
是的,你可以.您应该向目标添加一个Copy Files
构建阶段(右键单击您的目标,然后选择添加 > 新建构建阶段 > 新建复制文件构建阶段).
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).
将 Copy Files 构建阶段的目标设置为 Resources,路径为 Fonts
.这将确保将字体复制到应用程序包中名为 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.
通过将字体文件拖到构建阶段,将字体文件添加到新的构建阶段.
Add your font file to the new build phase by dragging the font file onto the build phase.
然后您需要添加 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屋!