Skip to content

Instantly share code, notes, and snippets.

@jbergen
Created November 18, 2014 20:38
Show Gist options
  • Save jbergen/f57fe6f958901900e711 to your computer and use it in GitHub Desktop.
Save jbergen/f57fe6f958901900e711 to your computer and use it in GitHub Desktop.
Print all available font families and font names (Swift)
for family in UIFont.familyNames() {
let sName: String = family as String
println("family: \(sName)")
for name in UIFont.fontNamesForFamilyName(sName) {
println("name: \(name as String)")
}
}
Copy link

ghost commented Oct 22, 2017

In Swift 4 which Xcode 9, the correct syntax is:

for family in UIFont.familyNames {

	let sName: String = family as String
	print("family: \(sName)")
            
	for name in UIFont.fontNames(forFamilyName: sName) {
		print("name: \(name as String)")
	}
}

@gundrabur
Copy link

Running this code leads to a lot warnings in Xcode 13 (and maybe in earlier versions as well):
CoreText note: Client requested name ".SFUI-Regular", it will get TimesNewRomanPSMT rather than the intended font. All system UI font access should be through proper APIs such as CTFontCreateUIFontForLanguage() or +[UIFont systemFontOfSize:]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment