UITabBar 外观适用于 iOS6 但不适用于 iOS 5
Posted
技术标签:
【中文标题】UITabBar 外观适用于 iOS6 但不适用于 iOS 5【英文标题】:UITabBar appearance works on iOS6 but not iOS 5 【发布时间】:2013-01-16 06:46:10 【问题描述】:我有一些代码来自定义 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 设置标签栏项目的文本属性的方法。
感谢任何帮助或提示! :-)
最好的祝愿, 托马斯
【问题讨论】:
【参考方案1】:好吧,外观代码并不是真正的问题。如前所述,我在
- (void)applicationDidFinishLaunching:(UIApplication *)application
该应用程序有点旧,Apple 文档指出,应该在 iOS3+ 上使用
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
我改变了它,现在它可以按预期工作了。
【讨论】:
以上是关于UITabBar 外观适用于 iOS6 但不适用于 iOS 5的主要内容,如果未能解决你的问题,请参考以下文章