Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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.

My code...

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];
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
408 views
Welcome To Ask or Share your Answers For Others

1 Answer

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).

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.

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>

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...