OGeek|极客世界-中国程序员成长平台

标题: cocoa-touch - 确定 iOS 上支持的字体样式的最佳方法是什么? [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-13 07:24
标题: cocoa-touch - 确定 iOS 上支持的字体样式的最佳方法是什么?

我无法找到一种简单的方法来确定字体是否支持 iOS 上的粗体或斜体字体样式。我当前的解决方案是基于尝试创建具有所需字体样式的 CTFont:

CTFontRef ctFont = CTFontCreateWithName(fontName, pointSize, NULL);
CTFontRef boldFont = CTFontCreateCopyWithSymbolicTraits(ctFont, 0.0, NULL, kCTFontBoldTrait, kCTFontBoldTrait);
if (boldFont) {
// supports bold font face
}

虽然这可以正常工作,但不知何故感觉并不是最好的方法。有没有更好的办法?



Best Answer-推荐答案


如果你使用 UIFont,我猜你可以迭代 fontNamesForFamilyName:

for (NSString *fontName : [UIFont fontNamesForFamilyName:fontName]) {
    if ([fontName rangeOfString"Bold"].location != NSNotFound) {
       //supports bold font face
    }
}

也许没有那么好......而且粗体字体并不总是用文本“粗体”来定义,有些使用浅色和中等字体。 http://www.iphonedevsdk.com/forum/iphone-sdk-development/6000-list-uifonts-available.html

关于cocoa-touch - 确定 iOS 上支持的字体样式的最佳方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5806256/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://sqlite.in/) Powered by Discuz! X3.4