在我的AppDelegate实现文件中,我使用这些代码行来设置tabBarItems的自定义字体和颜色:
[[UITabBarItem appearance] setTitleTextAttributes:
[NSDictionary dictionaryWithObjectsAndKeys:
[UIColor grayColor], UITextAttributeTextColor,
[UIFont fontWithName:@"Arial" size:0.0], UITextAttributeFont,
nil] forState:UIControlStateNormal];
[[UITabBarItem appearance] setTitleTextAttributes:
[NSDictionary dictionaryWithObjectsAndKeys:
[UIColor whiteColor], UITextAttributeTextColor,
[UIFont fontWithName:@"Arial" size:0.0], UITextAttributeFont,
nil] forState:UIControlStateHighlighted];
对于某些(未知)原因,将记录以下消息,每个tabBarItem一个:
button text attributes only respected for UIControlStateNormal, UIControlStateHighlighted and UIControlStateDisabled. state = 1 is interpreted as UIControlStateHighlighted.
使用标准搜索引擎无法找到任何内容,因此我寻求您的帮助。我做错了什么以及如何解决这个问题?
提前感谢您提出任何建议。
答案 0 :(得分:52)
只需将“UIControlStateHighlighted”更改为“UIControlStateSelected”即可。希望这有帮助!
答案 1 :(得分:7)
我有同样的问题,因为我正在使用:
[[UIBarButtonItem appearance] setTitleTextAttributes:
[NSDictionary dictionaryWithObjectsAndKeys:
[UIColor whiteColor], UITextAttributeTextColor, nil] forState:UIControlStateSelected];
我把它改为:
[[UIBarButtonItem appearance] setTitleTextAttributes:
[NSDictionary dictionaryWithObjectsAndKeys:
[UIColor whiteColor], UITextAttributeTextColor, nil] forState:UIControlStateHighlighted];
......问题消失了。希望这有帮助!