I'm unable to find an easy way to determine if a font supports the bold or italic font style on iOS. My current solution is based on trying to create a CTFont with the wished font style:
CTFontRef ctFont = CTFontCreateWithName(fontName, pointSize, NULL);
CTFontRef boldFont = CTFontCreateCopyWithSymbolicTraits(ctFont, 0.0, NULL, kCTFontBoldTrait, kCTFontBoldTrait);
if (boldFont) {
// supports bold font face
}
While this works fine, it somehow doesn't feel like the best way to do it. Is there a better way?
If you use UIFont I guess you could just iterate the fontNamesForFamilyName:
for (NSString *fontName : [UIFont fontNamesForFamilyName:fontName]) {
if ([fontName rangeOfString:@"Bold"].location != NSNotFound) {
//supports bold font face
}
}
Maybe not that much better... And a bold font isn't always defined with the text 'Bold', some use light and medium. http://www.iphonedevsdk.com/forum/iphone-sdk-development/6000-list-uifonts-available.html