简体   繁体   中英

How to use bold, regular and italic font styles for custom fonts?

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?

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

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

This function will give all fonts name.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM