2013-10-25 38 views
1

由於我沒有使用xib文件,並且不知何故,我的代碼結構根本沒有幫助我,所以我正面臨更改標籤欄顏色的麻煩,告訴我是否需要重寫整個事情從頭開始然而,如果我沒有^^^在沒有xib文件的情況下更改我的標籤欄顏色

我會非常感激這是我的appDelegate文件的單個視圖應用程序,在這裏我創建與導航欄相關聯的標籤欄每個選項卡,然後顯示這些

self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 
[self.window makeKeyAndVisible]; 

self.firstTab = [[FirstTab alloc] initWithNibName:nil bundle:NULL]; 
self.firstNavigationController = [[UINavigationController alloc] initWithRootViewController:self.firstTab]; 
self.thirdTab = [[ThirdTab alloc] initWithNibName:nil bundle:NULL]; 
self.thirdNavigationController = [[UINavigationController alloc] initWithRootViewController:self.thirdTab]; 
self.tab2 = [[newsecViewController alloc] initWithNibName:@"newsecViewController" bundle:NULL]; 
self.tab2NavigationController = [[UINavigationController alloc] initWithRootViewController:self.tab2]; 
self.tab2.view.backgroundColor = [UIColor purpleColor]; 



//NSArray *tabs = [[NSArray alloc] initWithObjects:self.firstTab, self.secondTab, self.thirdTab, nil]; 
NSArray *tabBars = [[NSArray alloc] initWithObjects:self.firstNavigationController, self.tab2NavigationController, self.thirdNavigationController, nil]; 
self.tabBarController = [[UITabBarController alloc] init]; 
[self.tabBarController setViewControllers:tabBars]; 
[self.window addSubview:self.tabBarController.view]; 

這是我的選項卡之一的碼樣本

self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; 
if(self != nil) { 
    self.title = @"Second"; 
    self.tabBarItem.image = [UIImage imageNamed:@"triangle.png"]; 

} 
return self; 

感謝所有您的幫助...

+0

你想改變哪種顏色?所有選項卡的整體顏色或所選選項卡圖像的色調?哪個版本的iOS? – rmaddy

回答

1

使用的TabBar的tintColor屬性。它在iOS 5.0及更高版本中可用。

[tabBarController.tabBar setTintColor:[UIColor purpleColor]]; 
+0

我試過了,但是這在某種程度上不起作用 –

+1

在iOS 7下,'tintColor'設置所選標籤圖像的顏色。使用iOS 7下的'barTintColor'色調實際的標籤。 – rmaddy

1

設置顏色時UINavigationBarUITabBar使用barTintColor屬性與iOS 7日開始。

[self.tabBarController.tabBar setBarTintColor:[UIColor purpleColor]]; 
相關問題