I've seen this question asked and answered numerous times, but I haven't seen a real answer. The common "solutions" are:
So the question is: How to dynamically load a font under iOS? Loading the font "dynamically" means loading any given font which is not known at the time of the app's compilation.
WebFont. load({ google: { families: ['Droid Sans'] }, timeout:5000, fontactive: function(familyName,fvd){ //This is called once font has been rendered in browser // Your business logic goes here }, }); You can also load custom fonts apart from google fonts.
You can download fonts from the App Store app , then use them in documents you create on iPhone. After you download an app containing fonts from the App Store, open the app to install the fonts. To manage installed fonts, go to Settings > General, then tap Fonts.
Add the Font File to Your Xcode Project To add a font file to your Xcode project, select File > Add Files to “Your Project Name” from the menu bar, or drag the file from Finder and drop it into your Xcode project. You can add True Type Font (. ttf) and Open Type Font (. otf) files.
Dynamic Type is an iOS feature that scales font according to the user settings. More than 40% of iOS users have changed the default system font size. Both larger and smaller. The easiest way to support Dynamic Type is to use System Font Styles either from Storyboard or programmatically with UIKit.
Fonts can easily be dynamically loaded from any location or any byte stream. See the article here: http://www.marco.org/2012/12/21/ios-dynamic-font-loading
NSData *inData = /* 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);
See also: https://developer.apple.com/library/mac/#documentation/Carbon/Reference/CoreText_FontManager_Ref/Reference/reference.html#//apple_ref/doc/uid/TP40008278
https://developer.apple.com/library/mac/#documentation/GraphicsImaging/Reference/CGFont/Reference/reference.html#//apple_ref/c/func/CGFontCreateWithDataProvider
Great time for a recent post from Marco titled Loading iOS fonts dynamically.
NSData *inData = /* your decrypted 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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With