开发者

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 开发者_JAVA技巧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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜