1.把test.ttf文件添加到工程中数组
2.在info.plist中添加Fonts provided by application(数组类型),数组中添加item test.ttf app
ps:ide
获取ttf字体名称字体
法1.遍历全部字体名称找到对应的spa
for( NSString *familyName in [UIFont familyNames] ){
NSLog( "Family: %s \n", [familyName UTF8String] );
for( NSString *fontName in [UIFont fontNamesForFamilyName:familyName] ){
NSLog( "\tFont: %s \n", [fontName UTF8String] );
}
}3d
法2.经过读取本地文件路径ip
NSString *path = [[NSBundle mainBundle] pathForResource:@"test" ofType:@"ttf"];it
NSURL *fontUrl = [NSURL fileURLWithPath:path];io
CGDataProviderRef fontDataProvider = CGDataProviderCreateWithURL((__bridge CFURLRef)fontUrl);class
CGFontRef fontRef = CGFontCreateWithDataProvider(fontDataProvider);
CGDataProviderRelease(fontDataProvider);
CTFontManagerRegisterGraphicsFont(fontRef, NULL);
NSString *fontName = CFBridgingRelease(CGFontCopyPostScriptName(fontRef));
CGFontRelease(fontRef);