Download font .ttf file from web and store on iPhone

后端 未结 5 598
余生分开走
余生分开走 2020-12-18 11:39

Is it possible to download .ttf file from web and store it on iPhone. Then use that for for labels and all other stuff ? Because my client want to control fonts from databas

5条回答
  •  死守一世寂寞
    2020-12-18 12:00

    Actually it is possible to dynamically add fonts to the iOS runtime like this:

    NSData *fontData = /* your font-file data */;
    CFErrorRef error;
    CGDataProviderRef provider = CGDataProviderCreateWithCFData((CFDataRef)inData);
    CGFontRef font = CGFontCreateWithDataProvider(provider);
    if (! CTFontManagerRegisterGraphicsFont(font, &error)) {
        CFStringRef errorDescription = CFErrorCopyDescription(error)
        NSLog(@"Failed to load font: %@", errorDescription);
        CFRelease(errorDescription);
    }
    CFRelease(font);
    CFRelease(provider);
    

    Source: This Blog Article of Marco Arment.

提交回复
热议问题