How do I get the font name from an otf or ttf file?

前端 未结 15 1591
-上瘾入骨i
-上瘾入骨i 2020-11-28 03:44

I have used a custom font in my previous app.

The file name was \"ProximaNova-Regular.otf\" and to load the font I just used...

[UIFont fontWithName:         


        
相关标签:
15条回答
  • 2020-11-28 04:09
    • Install the font
    • Open Font Book app on your Mac
    • Select the font and click on 'info' button
    • The name you're looking for is PostScript name
      • MacOS: View -> Show Font Info

    0 讨论(0)
  • 2020-11-28 04:10

    Log familyNames of font file and then access the fonts:

    // You can log all font family names suing **fontNamesForFamilyName**
    
    NSLog(@" font name %@", [UIFont fontNamesForFamilyName:@"the file name"]);
    

    Hope it helps you.

    0 讨论(0)
  • 2020-11-28 04:11

    Right click on the TTF -> Get Info

    "Full Name" is what you're looking for.

    That's what worked for me with TTFs.

    Edit:

    I just used a font that had a different name from the "Full Name" in Get Info.

    For the compilation of this answer, If the quick check above doesn't work, run this code in your project:

    for (NSString *fontFamilyName in [UIFont familyNames]) {
        for (NSString *fontName in [UIFont fontNamesForFamilyName:fontFamilyName]) {
            NSLog(@"Family: %@    Font: %@", fontFamilyName, fontName);
        }
    }
    

    And search for the correct name of the font you want to use.

    Swift 3.0 code:

    for fontFamilyName in UIFont.familyNames{
        for fontName in UIFont.fontNames(forFamilyName: fontFamilyName){
            print("Family: \(fontFamilyName)     Font: \(fontName)")
        }
    }
    
    0 讨论(0)
提交回复
热议问题