I wish to check at runtime whether a font exists on the device (iphone/ipad)?
Is there a way to do that?
you could try by using the UIFont
fontWithName method , i feel it should return nil for the font which does'nt exist in iOS.
+ (UIFont *)fontWithName:(NSString *)fontName size:(CGFloat)fontSize
You can use this code to get a list of all fonts available:
// List all fonts on iPhone
NSArray *familyNames = [[NSArray alloc] initWithArray:[UIFont familyNames]];
NSArray *fontNames;
NSInteger indFamily, indFont;
for (indFamily=0; indFamily<[familyNames count]; ++indFamily)
{
NSLog(@"Family name: %@", [familyNames objectAtIndex:indFamily]);
fontNames = [[NSArray alloc] initWithArray:
[UIFont fontNamesForFamilyName:
[familyNames objectAtIndex:indFamily]]];
for (indFont=0; indFont<[fontNames count]; ++indFont)
{
NSLog(@" Font name: %@", [fontNames objectAtIndex:indFont]);
}
[fontNames release];
}
[familyNames release];
Based on this code you can easily build an NSArray with all font names and then use it to verify if your font is there, or any kind of workflow is more appropriate to your app.
source
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