I have a list of font names in my app, which are all displayed in the font they represent. The following three do not work though:
ArialRoundedMTBold
ChalkboardSE-Bold
TrebuchetMS-Bold
Instead they display in the standard font.
Any ideas why these might not be showing up?
Go to File Explorer. Click View, then select Options. Click View. Choose Show hidden files, folders, and drives.
If Typekit fonts are not showing up in Adobe Applications then it's either because 1.) you need to enable Adobe fonts in the Creative Cloud settings, or 2.) you don't have Creative Cloud running.
If you want to see what a font looks like, open the Fonts folder, right-click the font file, and then click Preview. Another way to see your installed fonts is through Control Panel. In Windows 7 and Windows 10, go to Control Panel > Fonts. In Windows 8.1, go to Control Panel > Appearance and Personalization > Fonts.
To use a custom font (one not included in iOS) you have to edit your <appname>-Info.plist
file and create a new UIAppFonts
key with type array, where each element of the array is a String with the name of your font file. Example: VAGRoundedStd-Light.ttf
. You also have to add the file to your project.
Note: When you type UIAppFonts
and press enter, the key is converted to "Fonts provided by application".
However, when you use the font in Interface Builder (or with UIFont
) you don't use the filename of the font, but the name that appears when you open the font in the application Font Book of your Mac. For the previous example it would be VAG Rounded Std Light
.
OS X is more tolerant than iOS digesting TrueType formats, so on rare occasions you may find a font that works in OS X but not in iOS. If that happens, replace the font to see if at least you got the process right.
This solves the case where the font license requires you to distribute the font encrypted.
This following recipe is from Loading iOS fonts dynamically by Marco Arment. It makes the fonts available in UIFont and UIWebView. The same code can be used to load fonts from the Internet.
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);
This is the case where iOS refuses to load more than two fonts from the same family.
Here is a code workaround from stackoverflow user Evadne Wu. Simply stick the following in your app delegate (note that it uses two frameworks):
#import <CoreText/CoreText.h>
#import <MobileCoreServices/MobileCoreServices.h>
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
CTFontManagerRegisterFontsForURLs((__bridge CFArrayRef)((^{
NSFileManager *fileManager = [NSFileManager defaultManager];
NSURL *resourceURL = [[NSBundle mainBundle] resourceURL];
NSArray *resourceURLs = [fileManager contentsOfDirectoryAtURL:resourceURL includingPropertiesForKeys:nil options:0 error:nil];
return [resourceURLs filteredArrayUsingPredicate:[NSPredicate predicateWithBlock:^BOOL(NSURL *url, NSDictionary *bindings) {
CFStringRef pathExtension = (__bridge CFStringRef)[url pathExtension];
NSArray *allIdentifiers = (__bridge_transfer NSArray *)UTTypeCreateAllIdentifiersForTag(kUTTagClassFilenameExtension, pathExtension, CFSTR("public.font"));
if (![allIdentifiers count]) {
return NO;
}
CFStringRef utType = (__bridge CFStringRef)[allIdentifiers lastObject];
return (!CFStringHasPrefix(utType, CFSTR("dyn.")) && UTTypeConformsTo(utType, CFSTR("public.font")));
}]];
})()), kCTFontManagerScopeProcess, nil);
return YES;
}
Available as gist. Commented in the author blog: Loading 2+ fonts on iOS from the same font family.
An alternative, more involved workaround from pixeldock.com:
If you add more than 2 font variants of the same font family (e.g. “Normal”, “Bold” and “Extended”), only the last two font variants that you added to the project will be usable.
If you see this happening, it is a limitation of your SDK version, and the only way out of it is editing the font family with a Font editor like Fontforge. Again, from pixeldock.com:
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