Skip to content

Instantly share code, notes, and snippets.

@swissmanu
Last active December 20, 2015 09:49
Show Gist options
  • Save swissmanu/6110904 to your computer and use it in GitHub Desktop.
Save swissmanu/6110904 to your computer and use it in GitHub Desktop.
load a font from a custom ios/mac resource .bundle-file. via: http://stackoverflow.com/a/15510259/368959
- (void) loadCustomFont:(NSString*)fontFileName ofType:(NSString*)extension bundle:(NSBundle*)bundle {
NSString *fontPath = [bundle pathForResource:fontFileName ofType:extension];
NSData *inData = [NSData dataWithContentsOfFile:fontPath];
CFErrorRef error;
CGDataProviderRef provider = CGDataProviderCreateWithCFData((__bridge CFDataRef)inData);
CGFontRef font = CGFontCreateWithDataProvider(provider);
if (!CTFontManagerRegisterGraphicsFont(font, &error)) {
CFStringRef errorDescription = CFErrorCopyDescription(error);
NSLog(@"Failed to load font: %@", errorDescription);
CFRelease(errorDescription);
}
CFRelease(font);
CFRelease(provider);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment