自定义字体Xcode 4.3 [英] Custom Fonts Xcode 4.3

查看:129
本文介绍了自定义字体Xcode 4.3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在我的项目中使用此字体但它不会起作用。
我在我的项目中添加了.ttf文件,并在密钥下的MyApp-Info.plist中添加了它的名称:应用程序提供的字体。然后我尝试了这个:

I'm trying to use this font in my project but it won't work. I added the .ttf file in my project and added its name in the MyApp-Info.plist under the key: Fonts provided by application. Then I tried this:

 [_titleLabel setFont:[UIFont fontWithName:@"chalkboard" size:_titleLabel.font.pointSize]];

我还检查了字体的名称是否真的是黑板,它是。显示的字体仍然是Helvetica,只是更小。问题出在哪里?
提前致谢。

I also checked if the name of the font is really "chalkboard" and it is. The displayed font is still Helvetica, only smaller. Where could the problem be? Thanks in advance.

推荐答案

您需要使用字体名称,而不是文件名。字体名称在ttf文件中。

You need to use font name, not filename. Font name is inside the ttf file.

您可以在此处找到iOS的字体名称: http://iosfonts.com/

You can find font names for iOS here: http://iosfonts.com/

此代码将列出您应用中的所有字体名称,将其放在主控制器上的viewDidLoad中,运行应用程序,然后在控制台中找到正确的字体名称。

This code will list all your font names in your app, put it somewhere in viewDidLoad on main controller, run app and then in console found the right name for the font.

NSArray *familyNames = [[NSArray alloc] initWithArray:[UIFont familyNames]];

NSArray *fontNames;
NSInteger indFamily, indFont;
for (indFamily=0; indFamily<[familyNames count]; ++indFamily)
{
    NSLog(@"Family name: %@", [familyNames objectAtIndex:indFamily]);
    fontNames = [[NSArray alloc] initWithArray:
                 [UIFont fontNamesForFamilyName:
                  [familyNames objectAtIndex:indFamily]]];
    for (indFont=0; indFont<[fontNames count]; ++indFont)
    {
        NSLog(@"    Font name: %@", [fontNames objectAtIndex:indFont]);
    }
}

更新。

您还可以右键单击Finder中的字体文件,获取信息并复制全名。但它并不总是100%。

You can also right click on font file in Finder, get Info and copy full name. But it is not always 100%.

这篇关于自定义字体Xcode 4.3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆