美文网首页
获取自定义字体ttf的FontName

获取自定义字体ttf的FontName

作者: 海小城 | 来源:发表于2019-12-02 14:42 被阅读0次

    需要倒入#import <CoreText/CoreText.h>

    NSString *fontPath = [[NSBundle mainBundle] pathForResource:@"WriteFont" ofType:@"ttf"];

    NSURL *fontUrl = [NSURL fileURLWithPath:fontPath];

    CGDataProviderRef fontDataProvider = CGDataProviderCreateWithURL((__bridge CFURLRef)fontUrl);

    CGFontRef fontRef = CGFontCreateWithDataProvider(fontDataProvider);

    CGDataProviderRelease(fontDataProvider);

     CTFontManagerRegisterGraphicsFont(fontRef, NULL);

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

     CGFontRelease(fontRef);

      NSLog(@"获取字体FontName:%@", fontName);

    相关文章

      网友评论

          本文标题:获取自定义字体ttf的FontName

          本文链接:https://www.haomeiwen.com/subject/rkffgctx.html