简体   繁体   中英

Change font name AND weight in UILabel (iPhone SDK)

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?

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

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