我无法找到一种简单的方法来确定字体是否支持 iOS 上的粗体或斜体字体样式。我当前的解决方案是基于尝试创建具有所需字体样式的 CTFont:
CTFontRef ctFont = CTFontCreateWithName(fontName, pointSize, NULL);
CTFontRef boldFont = CTFontCreateCopyWithSymbolicTraits(ctFont, 0.0, NULL, kCTFontBoldTrait, kCTFontBoldTrait);
if (boldFont) {
// supports bold font face
}
虽然这很好用,但不知何故,它并不是最好的方法。有没有更好的办法?