UITabBar外观适用于iOS6但不适用于iOS 5

时间:2013-01-16 06:46:11

标签: ios ios5 ios6 uitabbar uitabbaritem

我有一些代码来自定义TabBar。我使用外观框架来做到这一点。该应用程序是iOS 5+,所以这应该是我理解的。我的代码如下所示:

NSDictionary *textAttributesNormal = @{
  UITextAttributeTextColor: [UIColor colorWithRed:0.04f green:0.25f blue:0.56f alpha:1.00f],
  UITextAttributeTextShadowOffset: [NSValue valueWithUIOffset:UIOffsetMake(0, 0)]
};

NSDictionary *textAttributesSelected = @{
  UITextAttributeTextColor: [UIColor colorWithWhite:1.0 alpha:1.0]
};


[[UITabBar appearance] setTintColor:[UIColor colorWithRed:0.53f green:0.76f blue:0.91f alpha:1.00f]];
[[UITabBarItem appearance] setTitleTextAttributes:textAttributesNormal forState:UIControlStateNormal];
[[UITabBarItem appearance] setTitleTextAttributes:textAttributesSelected forState:UIControlStateSelected];

我在委托的applicationDidFinishLaunching方法中执行此操作。此代码在iOS6上完美运行,并按预期运行。但是在iOS 5上它什么也没做。它既不会引发任何警告或错误。

模拟器和实际设备上的行为相同。我可以在界面构建器中设置色调颜色,然后它将在iOS5上运行。但我没有找到通过IF设置tabbar项的文本属性的方法。

我感谢任何帮助或暗示! : - )

祝福, 托马斯

1 个答案:

答案 0 :(得分:0)

好吧,外观代码不是实际问题。如上所述,我在

中这样做了
- (void)applicationDidFinishLaunching:(UIApplication *)application

该应用程序有点旧,Apple文档说明,在iOS3 +应该使用

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

我改变了它,现在它按预期工作。