NSString * fontPath = @"你的字体的本地路径";
CGDataProviderRef fontDataProvider = CGDataProviderCreateWithFilename([fontPath UTF8String]);
CGFontRef customfont = CGFontCreateWithDataProvider(fontDataProvider);
CGDataProviderRelease(fontDataProvider);
NSString *fontName = (__bridge NSString *)CGFontCopyFullName(customfont);
CFErrorRef error;
CTFontManagerRegisterGraphicsFont(customfont, &error);
if (error){
// 为了可以重复注册
CTFontManagerUnregisterGraphicsFont(customfont, &error);
CTFontManagerRegisterGraphicsFont(customfont, &error);
}
CGFontRelease(customfont);
font = [UIFont fontWithName:fontName size:fontSize];
网友评论