In my application I want to use the ttf in the documents directory. By referring to the link I use below code to use the font from CGFontRef
+ (UIFont *)loadFontAtPath:(NSString*)path{
NSData *data = [[NSFileManager defaultManager] contentsAtPath:path];
// path is "/Users/............./Documents/bloktilt.ttf"
if(data == nil){
NSLog(@"Failed to load font. Data at path is null");
return nil;
}
CFErrorRef error;
CGDataProviderRef provider = CGDataProviderCreateWithCFData((CFDataRef)data);
CGFontRef font = CGFontCreateWithDataProvider(provider);
NSString *fontName = (NSString *)CGFontCopyPostScriptName(font);
UIFont *font1 = [UIFont fontWithName:fontName size:15];
if(!CTFontManagerRegisterGraphicsFont(font, &error)){
CFStringRef errorDescription = CFErrorCopyDescription(error);
NSLog(@"Failed to load font: %@", errorDescription);
CFRelease(errorDescription);
}
CFRelease(font);
CFRelease(provider);
return font1;
}
But the problem is that the above code is returning nil