自定义字体在iOS 5中不起作用

时间:2013-06-11 05:32:00

标签: iphone ios ipad ios5 uifont

我在资源中添加了 Avenir-Next-LT-Pro-Demi-Condensed_5186.ttf 字体。同样添加到我的info.plist中的应用程序提供的字体。 在我的代码中,我设置了这样的字体,

titleLabel.font = [UIFont fontWithName:@"Avenir-Next-LT-Pro-Demi-Condensed_5186" size:10];

但这不适用于ios 5模拟器和设备。

4 个答案:

答案 0 :(得分:7)

试试这个,

The font name is not the font file name 

Avenir-Next-LT-Pro-Demi-Condensed_5186.ttf is a file name. simply double click the Avenir-Next-LT-Pro-Demi-Condensed_5186.ttf file it will automatically  open the font reader.Get the font name from top of the font reader navigation bar..

enter image description here

titleLabel.font = [UIFont fontWithName:@"Avenir Next LT Pro" size:10];

答案 1 :(得分:1)

你必须检查它与字体文件名不同的字体名称......

http://codefriends.blogspot.in/2012/04/adding-custom-font-in-xcode.html

得到Add Custom Fonts In Xcode 4.1

的答案

答案 2 :(得分:1)

按照以下步骤进行操作

1.请确保在复制font时选中"add to target"复选框。

2.首先在Finder中选择您的font节目并双击,确保您的font name必须与image

相同

enter image description here

此处字体名称为“eurofurence light”

3.将字体添加到.plist文件

4.做完所有事情后检查你的字体---

 NSLog(@"%@",[UIFont fontNamesForFamilyName:@"Your font"]);

根据font family使用BoldItalic ...

希望这会对你有所帮助

答案 3 :(得分:0)

我只想补充一下这个答案,并不是所有的时间都遵循这条规则。最好的方法是在应用程序中注册字体并执行快速检查并验证字体名称。

目标-C

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

斯威夫特

 for familyName in UIFont.familyNames() {
        for fontName in UIFont.fontNamesForFamilyName(familyName){
            print(fontName)
        }
    }