[UINavigationController外观]中的ios自定义字体titletextapperance崩溃应用程序

时间:2014-08-31 22:34:41

标签: ios

我有一个使用自定义字体的应用程序。我有问题使用Appearance属性设置导航栏的字体。

我已将字体添加到项目中,并将其添加到我的info.plist文件中。

这是我设置字体的颂歌:

[[UINavigationBar appearance] setTitleTextAttributes: @{NSForegroundColorAttributeName: [UIColor whiteColor],
                                                        NSFontAttributeName: [Refrigerator boldFontWithSize:24.0f]}];

这是我自定义的用于管理字体的Refridgerator对象:

+ (UIFont *)boldFontWithSize:(NSInteger)size {
    return [UIFont fontWithName:@"RefrigeratorDeluxe-Bold" size:size];
}

以下是我获得"正确"的截图。字体名称来自Font Book:

enter image description here

我得到的错误是:

[__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object from objects[1]

如果我将其更改为简单的类似" systemFont"那么错误就不会发生。

1 个答案:

答案 0 :(得分:0)

您必须使用UIAppFonts键将字体文件添加到Info.plist中。

您还可以使用;

检查字体名称的拼写
for (NSString *familyName in [UIFont familyNames]) {
    for (NSString *fontName in [UIFont fontNamesForFamilyName:familyName]) {
        NSLog(@"family: '%@' font: '%@'", familyName, fontName);
    }
}

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