ios第三方字体使用

2021-03-29  本文已影响0人  一盆酸菜鱼

不用在infoplist里添加key直接把字体文件拖拽到项目里调用。

+(UIFont*)customFontWithPath:(NSString*)path size:(CGFloat)size

{

    NSURL*fontUrl = [NSURLfileURLWithPath:path];

CGDataProviderReffontDataProvider =CGDataProviderCreateWithURL((__bridgeCFURLRef)fontUrl);

    CGFontReffontRef =CGFontCreateWithDataProvider(fontDataProvider);

    CGDataProviderRelease(fontDataProvider);

CTFontManagerRegisterGraphicsFont(fontRef, NULL);

    NSString *fontName = CFBridgingRelease(CGFontCopyPostScriptName(fontRef));

    UIFont*font = [UIFontfontWithName:fontNamesize:size];

    CGFontRelease(fontRef);

 returnfont;

}

上一篇下一篇

猜你喜欢

热点阅读