Skip to content

Instantly share code, notes, and snippets.

@ashikahmad
Last active July 27, 2017 20:28
Show Gist options
  • Save ashikahmad/6b3eb300e9e99fa16d66efa891e457e0 to your computer and use it in GitHub Desktop.
Save ashikahmad/6b3eb300e9e99fa16d66efa891e457e0 to your computer and use it in GitHub Desktop.
Prints all available fonts in console. Try pasting this code in 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)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment