It also helps to load encrypted fonts which could be required by some of the font license.
Loading Custom Font
123456789101112131415161718
#import <CoreText/CoreText.h>-(void)loadCustomFont{NSString*fontPath=[[NSBundlemainBundle]pathForResource:@"JOURNAL"ofType:@"TTF"];CFErrorReferror;CGDataProviderRefprovider=CGDataProviderCreateWithFilename([fontPathUTF8String]);CGFontReffont=CGFontCreateWithDataProvider(provider);if(!CTFontManagerRegisterGraphicsFont(font,&error)){CFStringReferrorDescription=CFErrorCopyDescription(error);NSLog(@"Failed to load font: %@",errorDescription);CFRelease(errorDescription);}CFRelease(font);CFRelease(provider);// eg. set the fontself.myFontLabel.font=[UIFontfontWithName:@"Journal"size:20];}
Loading Encrypted Font
To load encrypted font, use CGDataProviderCreateWithCFData with the decrypted font data:
12345
NSData*decryptedFontData=...;CFErrorReferror;CGDataProviderRefprovider=CGDataProviderCreateWithCFData((CFDataRef)decryptedFontData);CGFontReffont=CGFontCreateWithDataProvider(provider);// ... same code as above ...