Last active
December 20, 2015 09:49
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (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