Skip to content

Instantly share code, notes, and snippets.

@TimurAykutYildirim
Last active May 20, 2019 06:39
Show Gist options
  • Select an option

  • Save TimurAykutYildirim/51ee265e3a72febdd961662f30e9a20e to your computer and use it in GitHub Desktop.

Select an option

Save TimurAykutYildirim/51ee265e3a72febdd961662f30e9a20e to your computer and use it in GitHub Desktop.
How to list fonts in an iOS project with Objective-C
/*
Add following loop somewhere in your view.
It will list all the fonts and type names (which you need to write properly or app will crash)
In my case, i did presume like this:
#define FONT_LIGHT @"SF-Pro-Text-Light"
#define FONT_REGULAR @"SF-Pro-Text-Regular"
#define FONT_MEDIUM @"SF-Pro-Text-Medium"
#define FONT_BOLD @"SF-Pro-Text-Bold"
#define FONT_BLACK @"SF-Pro-Text-Heavy"
but when i run the code i see it like this:
(myViewController.m:147) SF Pro Text
(myViewController.m:151) SFProText-Heavy
(myViewController.m:151) SFProText-Bold
(myViewController.m:151) SFProText-Medium
(myViewController.m:151) SFProText-Light
(myViewController.m:151) SFProText-Regular
source: https://codewithchris.com/common-mistakes-with-adding-custom-fonts-to-your-ios-app/
*/
for (NSString* family in [UIFont familyNames])
{
NSLog(@"%@", family);
for (NSString* name in [UIFont fontNamesForFamilyName: family])
{
NSLog(@" %@", name);
}
}
@BoxDengJZ
Copy link

Swift:

for family in UIFont.familyNames{
            print("family, \(family):")
            for name in UIFont.fontNames(forFamilyName: family){
                print("      name: \(name) ")
            }
            print("\n\n")
        }

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