20

在我的 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.

使用标准搜索引擎找不到任何东西,所以我寻求您的帮助。我做错了什么以及如何解决这个问题?

提前感谢您的任何建议。

4

2 回答 2

51

只需将“UIControlStateHighlighted”更改为“UIControlStateSelected”。希望这可以帮助!

于 2012-11-21T07:42:37.653 回答
7

我遇到了同样的问题,因为我正在使用:

[[UIBarButtonItem appearance] setTitleTextAttributes:
 [NSDictionary dictionaryWithObjectsAndKeys:
  [UIColor whiteColor], UITextAttributeTextColor, nil] forState:UIControlStateSelected];

我将其更改为:

[[UIBarButtonItem appearance] setTitleTextAttributes:
 [NSDictionary dictionaryWithObjectsAndKeys:
  [UIColor whiteColor], UITextAttributeTextColor, nil] forState:UIControlStateHighlighted];

......问题就消失了。希望这可以帮助!

于 2012-07-16T12:05:01.767 回答