开发者

iOS font names: dashes versus no dashes

I have found that Core Graphics wants different font names than what UIFont accepts.

For instance, CG accepts "Helvetica Bold" but not "Helvetica-Bold", whereas UIFont is the reverse.

Is there any comprehens开发者_运维知识库ive list of fonts available online that clarifies what names are appropriate for each context?

Thanks.


Here's the code from this link but tightened. It's only for for UIFont:

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

but these names seem to work fine for CGFontRef too, so use (for instance):

CGContextSelectFont (context, "Didot-Bold", FONT_SIZE, kCGEncodingMacRoman);

of course you can use font.fontName.UTF8String to get from a UIFont....


The font name used by UIFont depends on the creator of the Font. Sometimes a font name for italic will end with Ita and sometimes -Italic - there is no clear naming rule for that. I came up with an implementation that handles all the differences and returns you the right UIFont for all font-family + font style combinations - so you don't have to hardcode the font name. You can see it at http://eclipsesource.com/blogs/2012/07/26/uifont-from-a-css-definition/

With the code I provide there, you can get your desired UIFont as easy as:

UIFont *myFont = [FontResolver fontWithDescription:@"font-family: Helvetica; font-size:17px; font-weight: bold; font-style: italic;"];

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜