其他分享
首页 > 其他分享> > swift 5.0打印字体和设置字体的一些问题

swift 5.0打印字体和设置字体的一些问题

作者:互联网

前言

项目中可能用不同的字体,如果又支持国际化,不同语言设置不同字体。

获取字体名字:

    func showAllFonts(){
        let familyNames = UIFont.familyNames
        
        var index:Int = 0
        
        for familyName in familyNames {
            
            let fontNames = UIFont.fontNames(forFamilyName: familyName as String)
            for fontName in fontNames
            {
                index += 1
                
                print("第 \(index) 个字体,字体font名称:\(fontName)")
            }
        }
    }

在项目中在iOS13.0以前这样用是没问题的:

"AKbalthomNagaFont" = "AKbalthom Naga";
"AKbalthomNagaFontBold" = "AKbalthom Naga Bold";

但是iOS13.0以后就会获取不到字体而出现闪退

正确用法:

"AKbalthomNagaFont" = "AKbalthomNaga";
"AKbalthomNagaFontBold" = "AKbalthomNaga-Bold";

END.

标签:5.0,index,fontName,fontNames,Bold,字体,familyNames,swift
来源: https://blog.csdn.net/smileKH/article/details/120721259