iOS 动态加载字体

2020-08-06  本文已影响0人  Acton393
       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];
上一篇 下一篇

猜你喜欢

热点阅读