修复错误设置自定义ios字体

时间:2012-11-27 10:10:24

标签: objective-c ios5 xcode4.5

我正在尝试使用外观代理设置自定义字体。

[[UILabel appearance] setTitleTextAttributes:@{
    UITextAttributeFont:[UIFont fontWithName:@"PT Sans Narrow" size:10.0]
}];

我已将ttf添加到我的项目中,并确认字体名称是正确的。

XCode给了我这个错误:

2012-11-27 02:04:00.002 dashboard-mock[17093:11303] -[_UIAppearance setTitleTextAttributes:]: unrecognized selector sent to instance 0x712a1c0
2012-11-27 02:04:00.002 dashboard-mock[17093:11303] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[_UIAppearance setTitleTextAttributes:]: unrecognized selector sent to instance 0x712a1c0'
*** First throw call stack:
(0x1c92012 0x10cfe7e 0x1d1d4bd 0x1c81bbc 0x1c8194e 0x2aec 0x147b7 0x14da7 0x15fab 0x27315 0x2824b 0x19cf8 0x1beddf9 0x1bedad0 0x1c07bf5 0x1c07962 0x1c38bb6 0x1c37f44 0x1c37e1b 0x157da 0x1765c 0x28cd 0x27f5)
libc++abi.dylib: terminate called throwing an exception

我做错了什么?

2 个答案:

答案 0 :(得分:1)

-setTitleTextAttributes功能

时,您正在使用UINavigationBar标签
if([[UINavigationBar appearance] respondsToSelector:@selector(setTitleTextAttributes:)])
   [[UINavigationBar appearance] setTitleTextAttributes:@{
                         UITextAttributeFont:[UIFont systemFontOfSize:12],
                    UITextAttributeTextColor:[UIColor redColor]
}];

感谢

答案 1 :(得分:0)

想出来,它是setFont而不是setTitleTextAttributes

[[UILabel appearance] setFont:[UIFont fontWithName:@"PT Sans Narrow" size:10.0]];