xcode custom ttf font not working

后端 未结 2 787
梦毁少年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!

提交回复
热议问题