Listing Available Fonts on iOS

Note: This is an older post which was migrated to Ghost.

iOS allows you to include and use custom fonts inside your app. This has been the case for a long time, but using custom fonts is increasing in popularity lately. However, actually using a custom font can be tricky, due to incoherent naming.

The file name usually isn’t accurate, so you should look at the font’s system name, but even the system name isn’t always properly displayed, not even in a font manager. In these cases, you can use the snippet below to log a list of all available font families and its styles in the console.

[[UIFont familyNames] enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
    NSLog(@"%@", obj);
    [[UIFont fontNamesForFamilyName:obj] enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
        NSLog(@"-- %@", obj);
    }];
}];

Update: Swift version

for family in UIFont.familyNames() {  
    print("\(family)")
    for font in UIFont.fontNamesForFamilyName(family as! String) {
        print("-- \(font)")
    }
}
Erik van der Wal

Erik van der Wal

I love building things with Swift, Objective-C, Ruby and tinkering with technologies like Golang and Elixir.

  • The Netherlands
comments powered by Disqus