Skip to main content

Adding a custom font to an Xcode project for Mac OS

·223 words·2 mins

I needed to add a custom font to a project today and had real trouble finding how to do it. There were lots and lots of iOS tutorials, with this being the best of them. But I was doing a Mac OS app, not an iOS app, and so the tutorial didn’t quite fit my needs.

In the end, a coworker helped me figure out what I was doing wrong. So here’s a quick set of steps, based on the Code with Chris link above.

  1. Include the fonts in your Xcode project.

  2. Make sure they’re included in the target you’re building.

  3. Double-check that they’re being copied as resources into the product bundle.

  4. Include the folder with your fonts in the app Plist. On Mac OS you need to use ATSApplicationFontsPath instead of UIAppFonts. Important: Don’t think you can leave this out just because your fonts aren’t in a subfolder! Even if they’re loose in Resources, you need to supply a path. Just use “.” in that case.

  5. Find the name of the font. On OS X, you can use this line:

    NSLog(@"%@",[[NSFontManager sharedFontManager] availableFontFamilies]);
  6. Use NSFont and NSAttributedString to create a string using the font:

      NSFont *font = [NSFont fontWithName:@"MyFont" size:20.0];
      NSDictionary *attributes = @{NSFontAttributeName : font};
      NSAttributedString *attString = [[NSAttributedString alloc] initWithString:@"But a virgin Wurlitzer heart never once had a song" attributes:attributes];