文字ttf文件"/>
ios 在项目中使用文字ttf文件
1.把test.ttf文件添加到工程中
2.在info.plist中添加Fonts provided by application(数组类型),数组中添加item test.ttf
ps:
获取ttf字体名称
法1.遍历所有字体名称找到对应的
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] );
}
}
法2.通过读取本地文件路径
NSString *path = [[NSBundle mainBundle] pathForResource:@"test" ofType:@"ttf"];
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));
CGFontRelease(fontRef);
转载于:.html
更多推荐
ios 在项目中使用文字ttf文件
发布评论