Skip to content

Instantly share code, notes, and snippets.

@waynehartman
Last active January 10, 2018 04:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save waynehartman/8a3a5d8e41164f48409a0adc0fb5374f to your computer and use it in GitHub Desktop.
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.
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