How to use bold, regular and italic font styles fo

2019-08-18 06:58发布

问题:

I am currently using the font Yoxall in my app, and have .ttf files for "Regular", "Bold", and "Italic". I am currently using the coke [UIFont fontWithName:@"Yoxall" size:20.0f] to set the font as the regular Yoxall, using the YOXALL__.ttf file in my supporting files. I would also like to use italic Yoxall elsewhere in my app, but I obviously cannot call the same method, as "Yoxall" refers to both these files.

What code would I use to distinguish between the regular, bold, and italic styles of this font?

回答1:

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

This function will give all fonts name.



回答2:

Use +[UIFont familyNames] to list of all font family names known to the system, you can use +[UIFont fontNamesForFamilyName:] to list all of the font names known to the system.

Example code:

static void dumpAllFonts() {
    for (NSString *familyName in [UIFont familyNames]) {
        for (NSString *fontName in [UIFont fontNamesForFamilyName:familyName]) {
            NSLog(@"%@", fontName);
        }
    }
}

in output you can get font name. hope it's help