How to get an array of all installed fonts on iOS

448 Views Asked by At

iOS 16 allows to install custom fonts. They are listed in SettingsGeneralFonts.

I too want to display a list of the installed fonts in my app.

I did try using UIFont.familyNames as well as CTFontManagerCopyAvailableFontFamilyNames() but both return what seems to me like a list of fonts that are shipped with iOS itself, without the custom installed ones.

In other words: I do have installed custom fonts that show up in the Settings.app but did not appear when calling one of the mentioned functions.

How can I get a list of all installed fonts on iOS?

2

There are 2 best solutions below

0
ixany On BEST ANSWER

I found out two ways to access custom fonts.

Accessing all fonts on iOS is possible when using UIFontPickerViewController. The downside of this approach is that the picker itself is barely customizable.

Alternatively if you do know the postscript names of the required custom fonts you can request them directly using CTFontManagerRequestFonts(_:_:)

Please note that you’ll also need to add the Font entitlement to your Xcode project as described here.

1
Dhruv Saraswat On

This article suggests that we can, in fact, get the list of all fonts (including custom fonts) in the app using UIFont.familyNames

Copy-pasting the code snippet below, in case the link doesn't work :-

for family: String in UIFont.familyNames {
    print(family)
    for names: String in UIFont.fontNames(forFamilyName: family) {
        print("== \(names)")
    }
}

This code snippet provides an output similar to what is shown below :-

Kohinoor Telugu
== KohinoorTelugu-Regular
== KohinoorTelugu-Medium
== KohinoorTelugu-Light
Heiti TC
Quicksand
== Quicksand-Regular
== Quicksand-Light
== Quicksand-BoldItalic
== QuicksandDash-Regular
== Quicksand-LightItalic
== Quicksand-Bold
== Quicksand-Italic