Skip to content

Instantly share code, notes, and snippets.

@programmingthomas
Created November 1, 2013 19:35
Show Gist options
  • Save programmingthomas/7270732 to your computer and use it in GitHub Desktop.
Save programmingthomas/7270732 to your computer and use it in GitHub Desktop.
A simple Objective-C method that will register all of the TTF font files in your application with Core Text.
+ (void)registerFonts {
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
NSArray * paths = [[NSBundle mainBundle] pathsForResourcesOfType:@"ttf" inDirectory:@""];
for (NSString * path in paths) {
NSURL * url = [NSURL fileURLWithPath:path];
CFErrorRef error;
CTFontManagerRegisterFontsForURL((__bridge CFURLRef)url, kCTFontManagerScopeNone, &error);
error = nil;
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment