Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom font in a Cocoa application

I know you can customize fonts by using Interface Builder and selecting a font. However, I'm curious if I can use a custom font that's not included by default on systems. Is there a way to include a custom font in my application?

like image 758
sudo rm -rf Avatar asked Mar 12 '11 15:03

sudo rm -rf


People also ask

How do I add custom fonts to Xcode?

To add a font file to your Xcode project, select File > Add Files to “Your Project Name” from the menu bar, or drag the file from Finder and drop it into your Xcode project. You can add True Type Font (. ttf) and Open Type Font (. otf) files.


1 Answers

While the manual font activation procedure is one option, you might also consider the ATSApplicationFontsPath Info.plist key:

Information Property List Key Reference:

"ATSApplicationFontsPath (String - Mac OS X) identifies the location of a font file or directory of fonts in the bundle’s Resources directory. If present, Mac OS X activates the fonts at the specified path for use by the bundled application. The fonts are activated only for the bundled application 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."

I'd be sure to double-check, but I believe this functionality was added in OS X 10.5.x (which the code posted by Jinhyung Park targets).

like image 115
NSGod Avatar answered Sep 24 '22 07:09

NSGod