tags:

views:

140

answers:

1

Maybe I'm looking at the wrong place, however how do I set an UILabel's font and AND its weight?

Looking at the documentation, there seems to be only methods to create an UIFont with a given font name and size, like

[UIFont fontWithName:@"Helvetica" size:22])

OR create a bold font, with

[UIFont boldSystemFontOfSize:22]

How can I use these both together?

A: 

The documentation for fontWithName:size: states, "...name incorporates both the font family and the specific style information for the font."

So you probably want:

[UIFont fontWithName:@"Helvetica-Bold" size:22];

fontNamesForFamilyName: is handy for getting a list of available fonts for a given family.

For example:

NSArray* fontNames = [UIFont fontNamesForFamilyName:@"Helvetica"];
for( NSString* aFontName in fontNames ) {
    NSLog( @"Font name: %@", aFontName );
}

...which outputs:

Font name: Helvetica-BoldOblique
Font name: Helvetica
Font name: Helvetica-Oblique
Font name: Helvetica-Bold
zpasternack
Excellent. I was trying the "global" family names, and didn't pay attention to the families of each font as well. Thanks.
Rafael Steil