2014-06-13 86 views
0

我在一個項目中工作,我需要在此實現標籤欄控制器。我的標籤欄的背景色爲黑色,我用這下面的代碼:標籤欄背景顏色不會在ios6中更改

[[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)]; 
[email protected]"Home"; 
[email protected]"Connect"; 
[email protected]"About"; 
[email protected]"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中標籤欄屬性的任何事情?任何幫助將不勝感激。

回答

2

那麼他們的iOS 7改變了很多關於顏色的蘋果閱讀人機界面指南: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 
}