Question

I need to create UIFont with Helvetica-Regular, I use this code:

UIFont *font = [UIFont fontWithName:@"Helvetica-Regular" size:size];

But font is nill. How to do that correctly?

Was it helpful?

Solution

Well you can view the list of fonts supported by iOS here . The font Helvetica Regular does not feature in this list. If you want to go for this font name specifically then you would have to add this as a custom font. Or you could simply use the Helvetica font name. To go for the custom fonts you could browse through these links :-

How to use custom fonts in iPhone SDK?

How to include and use new fonts in iPhone SDK?

OTHER TIPS

There is no font name as Helvetica-regular

You can use form following

Helvetica
Helvetica-Bold
Helvetica-BoldOblique
Helvetica-Light
Helvetica-LightOblique
Helvetica-Oblique

The Debugger helps to find the types of font available :-

(lldb) po [UIFont fontNamesForFamilyName:@"Helvetica"]

(id) $1 = 0x079d8670 <__NSCFArray 0x79d8670>(
Helvetica
Helvetica-Bold
Helvetica-BoldOblique
Helvetica-Light
Helvetica-LightOblique
Helvetica-Oblique
    )

So,you can try for anyone of them.

Courtesy :- https://stackoverflow.com/a/11741389/1865424

Helvetica-Regular is not there as font name in iOS. For more details for font names check this link with iOS versionwise.

UIFont *font = [UIFont fontWithName:@"Helvetica" size:size];

To discover all available Fonts and their names:

+(void)dumpDescriptionOfAllAvailableFonts {

    NSMutableArray *allFonts = [NSMutableArray array];
    NSLog(@"%d font families", [[UIFont familyNames] count]);
    for(NSString *familyName in [UIFont familyNames]) {
        for(NSString *fontName in [UIFont fontNamesForFamilyName:familyName]) {
            [allFonts addObject:fontName];
        }
    }

    NSLog(@"%d fonts", [allFonts count]);

    for(NSString *fontName in [allFonts sortedArrayUsingDescriptors:@[[NSSortDescriptor sortDescriptorWithKey:@"description" ascending:YES]]]) {
        NSLog(@"%@",[fontName description]);
    }
}

You can log all of the available styles for a particular font family like this:

NSLog(@"%@", [UIFont fontNamesForFamilyName:@"Helvetica"]) ;

>

FontTest[41050:c07] (
    "Helvetica-LightOblique",
    Helvetica,
    "Helvetica-Oblique",
    "Helvetica-BoldOblique",
    "Helvetica-Bold",
    "Helvetica-Light"
)

You are probably after staight "Helvetica"...

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top