Last active
January 10, 2018 04:02
-
-
Save waynehartman/8a3a5d8e41164f48409a0adc0fb5374f to your computer and use it in GitHub Desktop.
There a number of posts out there that simply print the loaded fonts on iOS. This is a little bit more involved to sort and pretty print them to the console to easily determine what fonts have been loaded by visually scanning the list.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension UIFont { | |
public static func prettyPrintFontNames() { | |
var fonts = [String:[String]]() | |
for fontFamilyName in UIFont.familyNames { | |
for fontName in UIFont.fontNames(forFamilyName: fontFamilyName) { | |
var collection = fonts[fontFamilyName] ?? [String]() | |
collection.append(fontName) | |
fonts[fontFamilyName] = collection.sorted() | |
} | |
} | |
for family in fonts.keys.sorted() { | |
print(family) | |
if let collection = fonts[family] { | |
for font in collection { | |
print("\t\(font)") | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment