xcode custom ttf font not working

后端 未结 2 781
梦毁少年i
梦毁少年i 2020-12-25 11:21

ok so I\'ve been reading through SO and doing all sorts of googling but I cant figure out why my font isn\'t working.

I think I\'ve done everything right, but when

相关标签:
2条回答
  • 2020-12-25 11:34

    Another possibility is that you might be calling the wrong font name when you try to call your font. Use:

    Swift 2.1+

    //Check which fonts available
    for family: String in UIFont.familyNames()
    {
       print("\(family)")
       for names: String in UIFont.fontNamesForFamilyName(family)
       {
           print("== \(names)")
       }
    }
    

    Objective C

    //Check which fonts available
    for (NSString* family in [UIFont familyNames])
    {
        NSLog(@"FONT %@", family);
    
        for (NSString* name in [UIFont fontNamesForFamilyName: family])
        {
            NSLog(@"  %@", name);
        }
    }
    

    To find the actual names of the fonts you should be using with UIFont(name: "yourFontName", size: 24.0) (swift) or [UIFont fontWithName:@"yourFontName" size:16.0f] (obj c). The custom font names you add to your plist must match whatever the files are called in your directory (including the .ttf or .otf), but the code referencing the fonts must match the font names you get from this output. Good luck fontmasters!

    0 讨论(0)
  • 2020-12-25 11:58

    I would suspect that you haven't added the font file to your target, so that it's not copied to the app's resources. Your code works fine here and the font does show up as "Press Start K" in the list of font families.

    0 讨论(0)
提交回复
热议问题