iOS 动态加载自定义字体

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];

你可能感兴趣的:(iOS 动态加载自定义字体)