swift 在控制台中打印所有可用字体。尝试在Xcode Playground中粘贴此代码。

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了swift 在控制台中打印所有可用字体。尝试在Xcode Playground中粘贴此代码。相关的知识,希望对你有一定的参考价值。

import UIKit

/*
Prints all available fonts in console. Try pasting this code in Xcode Playground
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

┌───────────┐
│ All Fonts │
└┬──────────┘
 ├─┬─⦿ Family with fonts
 │ ├───⦿ Font 1
 │ └───⦿ Font 2
 ...
 ├───⦿ Family without fonts
 │
 └─┬─⦿ Last Family
   ├───⦿ Font 1
   ├───⦿ Font 1
   └───⦿ Font 1
 */

print("┌───────────┐")
print("│ All Fonts │")
print("└┬──────────┘")

let familyNames = UIFont.familyNames
let lastIndex = familyNames.count-1
let bullet = "⦿"
for i in 0...lastIndex {
    let isLastFamily = (i == lastIndex)
    let family = familyNames[i]
    let fontNames = UIFont.fontNames(forFamilyName: family)
    let br1 = isLastFamily ? " └" : " ├"
    let br2 = fontNames.count == 0 ? "─" : "┬"
    print(br1+"─"+br2+"─"+bullet+" "+family)
    if fontNames.count > 0 {
        let lastFontIndex = fontNames.count-1
        for k in 0...lastFontIndex {
            let font = fontNames[k]
            let br1 = isLastFamily ? " " : "│"
            let br2 = (k == lastFontIndex) ? "└─" : "├─"
            print(" "+br1+" "+br2+"──"+bullet+" "+font)
            if k == lastFontIndex {
                print(" "+br1)
            }
        }
    } else {
        let ch1 = isLastFamily ? "   " : " │ "
        print(ch1)
    }
    
}

以上是关于swift 在控制台中打印所有可用字体。尝试在Xcode Playground中粘贴此代码。的主要内容,如果未能解决你的问题,请参考以下文章

swift4.2 打印所有系统字体

在swift 4下更改导航控制器后退按钮的字体

上古卷轴5控制台上怎样修改字体大小

警告 - 尝试在 Swift 中呈现 UIAlertController null

准备继续不发送所有信息(Swift)

Json解析Swift没有得到打印