1.导入项目,这个就不说了
2.在info.plist添加
3.注意,font的name不是文件名,而是字体自己的名字,比如上面的young_man.oft
, 获取出来的字体名是WenYue-XinQingNianTi-NC-W8
获取方法如下:
NSString *path = oft的path;
NSURL *fontUrl = [NSURL fileURLWithPath:path];
CGDataProviderRef fontDataProvider = CGDataProviderCreateWithURL((__bridge CFURLRef)fontUrl);
CGFontRef fontRef = CGFontCreateWithDataProvider(fontDataProvider);
CGDataProviderRelease(fontDataProvider);
CTFontManagerRegisterGraphicsFont(fontRef, NULL);
NSString *fontName = CFBridgingRelease(CGFontCopyPostScriptName(fontRef));
4.在项目使用fontname来获取
UIFont *font = [UIFont fontWithName:@"WenYue-XinQingNianTi-NC-W8" size:11];