简体   繁体   中英

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. 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.

This seems to relate to the fact that in ios6 the bar backgroundcolor was tintColor and in ios 7 this was changed to 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.

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?

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. 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 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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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