我正在一个项目中工作,我需要在此实现标签栏控制器。我的标签栏背景颜色为黑色,我使用以下代码:
[[UITabBar appearance] setTintColor:[UIColor blackColor]]; UITabBarItem *tabBarItem1 = [tabBarController.tabBar.items objectAtIndex:0]; UITabBarItem *tabBarItem2 = [tabBarController.tabBar.items objectAtIndex:1]; UITabBarItem *tabBarItem3 = [tabBarController.tabBar.items objectAtIndex:2]; UITabBarItem *tabBarItem4 = [tabBarController.tabBar.items objectAtIndex:3]; [ tabBarItem1 setImageInsets:UIEdgeInsetsMake(2,0,-2,0)]; [ tabBarItem2 setImageInsets:UIEdgeInsetsMake(2,0,-2,0)]; [ tabBarItem3 setImageInsets:UIEdgeInsetsMake(2,0,-2,0)]; [ tabBarItem4 setImageInsets:UIEdgeInsetsMake(2,0,-2,0)];
tabBarItem1.title=@"Home";
tabBarItem2.title=@"Connect";
tabBarItem3.title=@"About";
tabBarItem4.title=@"Settings";
[[UITabBarItem appearance] setTitleTextAttributes:
[NSDictionary dictionaryWithObjectsAndKeys:
[UIColor colorWithRed:139.0/255.0 green:189.0/255.0 blue:208.0 alpha:255.0], 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:UIControlStateSelected];
[tabBarItem1 setFinishedSelectedImage:[self imageWithImage:[UIImage imageNamed:@"home_icon_selected.png"] scaledToSize:CGSizeMake(24, 18)] withFinishedUnselectedImage:[self imageWithImage:[UIImage imageNamed:@"home_icon.png"] scaledToSize:CGSizeMake(24, 18)]];
[tabBarItem2 setFinishedSelectedImage:[self imageWithImage:[UIImage imageNamed:@"connect_icon_selected.png"] scaledToSize:CGSizeMake(24, 18)] withFinishedUnselectedImage:[self imageWithImage:[UIImage imageNamed:@"connect_icon.png"] scaledToSize:CGSizeMake(24, 18)]];
[tabBarItem3 setFinishedSelectedImage:[self imageWithImage:[UIImage imageNamed:@"about_icon_selected.png"] scaledToSize:CGSizeMake(24, 18)] withFinishedUnselectedImage:[self imageWithImage:[UIImage imageNamed:@"about_icon.png"] scaledToSize:CGSizeMake(24, 18)]];
[tabBarItem4 setFinishedSelectedImage:[self imageWithImage:[UIImage imageNamed:@"settings_icon_selected.png"] scaledToSize:CGSizeMake(24, 18)] withFinishedUnselectedImage:[self imageWithImage:[UIImage imageNamed:@"settings_icon.png"] scaledToSize:CGSizeMake(24, 18)]];
self.tabBarController.tabBar.tintColor = [UIColor whiteColor];
>
在ios7中工作正常,但在ios6中没有反映出这一行。在ios6中是否还有其他我需要实现的东西或者我对标签栏属性的任何遗漏?任何帮助将不胜感激。
答案 0 :(得分:2)
他们在iOS 7中改变了很多颜色。阅读Apple的人机界面指南:https://developer.apple.com/library/ios/documentation/userexperience/conceptual/MobileHIG/index.html
以下是代码:
//check if this is not iOS 7
if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_6_1) {
//your code above except last line
//Tint is background in iOS 6 but text color in iOS 7
self.tabBarController.tabBar.tintColor = [UIColor blackColor];
}else{
//your code above
}