1

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

[[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

我究竟做错了什么?

4

2 回答 2

1

您正在使用-setTitleTextAttributes标签,而它是UINavigationBar功能

if([[UINavigationBar appearance] respondsToSelector:@selector(setTitleTextAttributes:)])
   [[UINavigationBar appearance] setTitleTextAttributes:@{
                         UITextAttributeFont:[UIFont systemFontOfSize:12],
                    UITextAttributeTextColor:[UIColor redColor]
}];

谢谢

于 2012-11-27T10:21:08.693 回答
0

想通了,setFont而不是setTitleTextAttributes

[[UILabel appearance] setFont:[UIFont fontWithName:@"PT Sans Narrow" size:10.0]];
于 2012-11-27T12:26:34.907 回答