简体   繁体   English

使用xcode 5界面构建器设置选项卡栏色调(背景)颜色

[英]using xcode 5 interface builder for setting tab bar tint (background) color

I am quite new to ios development and I have the following question. 我对ios开发很陌生,我有以下问题。 While designing a tabBar in a storyboard in xcode 5 I realized that I can't set the background color of the tabBar for ios 6. 在xcode 5的情节提要中设计tabBar时,我意识到我无法为ios 6设置tabBar的背景色。

This seems to relate to the fact that in ios6 the bar backgroundcolor was tintColor and in ios 7 this was changed to barTintColor. 这似乎与以下事实有关:在ios6中,bar backgroundcolor为tintColor,而在ios 7中,其变为了barTintColor。

If I change the storyboard "View as" parameter to "iOS 6.1 and Ealier" I see that the background color changes from the right value which I did set up in the attribut editor (Bar Tint) to the standard value of iOS 6. 如果将情节提要的“查看方式”参数更改为“ iOS 6.1和Ealier”,则会看到背景颜色从我在属性编辑器(Bar Tint)中设置的正确值更改为iOS 6的标准值。

Of course I can set the value from code but this would be bad for maintainability. 当然,我可以从代码中设置值,但这对可维护性不利。

Is there I way how one can define this value for iOS 6 in the xcode 5 interface builder? 有什么办法可以在xcode 5接口构建器中为iOS 6定义此值?

UPDATE: Since I don't found a satisfying solution for this problem up to now I use the following workaround. 更新:由于到目前为止,我还没有找到令人满意的解决方案,因此我使用以下解决方法。 I set the background color of the tabBar in the attribute inspector to the attributes "Bar Tint" and "Background" from the View. 我在属性检查器中将tabBar的背景色设置为视图中的属性“ Bar Tint”和“ Background”。 In my app delegate I use the following code: 在我的应用程序委托中,我使用以下代码:

UITabBarController *tabBarController = (UITabBarController *)self.window.rootViewController;
UITabBar *tabBar = tabBarController.tabBar;

if ([[[UIDevice currentDevice] systemVersion] floatValue] < 7) {
    [tabBar setSelectedImageTintColor:tabBar.tintColor];
    tabBar.tintColor = tabBar.backgroundColor;
}

I ran into the same issue. 我遇到了同样的问题。 Unfortunately you will have to preserve the iOS 6 compatibility in code, using something similar to this: 不幸的是,您将必须使用类似于以下内容的代码来保留iOS 6的兼容性:

// iOS 6 compatibility
NSString *reqSysVer = @"7.0";
NSString *currSysVer = [[UIDevice currentDevice] systemVersion];

if ([currSysVer compare:reqSysVer options:NSNumericSearch] == NSOrderedAscending) {
    [[UINavigationBar appearance] setTintColor:[UIColor colorWithRed:66.f/255.f green:173.f/255.f blue:179.f/255.f alpha:1.f]];
    [[UIBarButtonItem appearance] setTintColor:[UIColor colorWithRed:66.f/255.f green:173.f/255.f blue:179.f/255.f alpha:1.f]];
}

I'm not sure why the 'tint' in InterfaceBuilder does not work, but that isn't on our end. 我不确定InterfaceBuilder中的'tint'为什么不起作用,但这不是我们的目的。

Note: if you want to support iOS < 5.0 you will have to modify the iOS version check, since the UIAppearance protocol is only available since iOS 5.0 注意:如果要支持iOS <5.0,则必须修改iOS版本检查,因为UIAppearance协议仅在iOS 5.0之后可用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM