Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Download font .ttf file from web and store on iPhone

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 database and don't want to just drop fonts to xcode project right away.

So in future if he wants to change font, he will add new font to database, app will recognize new font on web (thats already done with images, not a problem), download it and use as font.

Thanks.

like image 822
zhuber Avatar asked Dec 05 '25 04:12

zhuber


1 Answers

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.

like image 82
calimarkus Avatar answered Dec 07 '25 19:12

calimarkus



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!