我正在尝试以编程方式更改tabbar项目文本的颜色。 我正在使用
[[UITabBar appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
[UIFont fontWithName:@"AmericanTypewriter" size:20.0f], UITextAttributeFont,
[UIColor blackColor], UITextAttributeTextColor,
[UIColor grayColor], UITextAttributeTextShadowColor,
[NSValue valueWithUIOffset:UIOffsetMake(0.0f, 1.0f)], UITextAttributeTextShadowOffset,
nil]];
哪个适用于iOS5及以上版本。 但是我的应用程序在控制台上因错误而崩溃:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[_UIAppearance setTitleTextAttributes:]: unrecognized selector sent to instance 0x79f5790'
*** First throw call stack:
不确定,为什么我会崩溃。 如果还有其他方法可以更改tabbar项的字体颜色,请另外建议。
由于
答案 0 :(得分:2)
这些答案都不正确(至少对iOS 6而言)。
在通话结束时你遗漏了forState:
。
实施例
[[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
[UIColor whiteColor], UITextAttributeTextColor,
[UIColor grayColor], UITextAttributeTextShadowColor,
[NSValue valueWithUIOffset:UIOffsetMake(0.0f, 1.0f)], UITextAttributeTextShadowOffset,
nil] forState:UIControlStateNormal];
答案 1 :(得分:1)
标题不属于UITabBar
但UITabBarItem
因此取代UITabBar
:
[[UITabBarItem appearance] setTitleTextAttributes:
答案 2 :(得分:1)