2013-10-25 3 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; 

Спасибо всем за вашу помощь ... tintColor недвижимость

+0

Какой цвет вы хотите изменить? Общий цвет всех вкладок или оттенок выбранного изображения вкладки? Какая версия iOS? – rmaddy

ответ

1

Используйте TabBar в. Он доступен в iOS 5.0 и более поздних версиях.

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

Я попытался, но это как-то не работает –

+1

В iOS 7 «tintColor» устанавливает цвет изображения выбранной вкладки. Используйте «barTintColor» под iOS 7, чтобы подкрасить фактические вкладки. – rmaddy

1

Начиная с прошивкой 7, при установке цвета UINavigationBar и UITabBar использовать barTintColor свойства.

[self.tabBarController.tabBar setBarTintColor:[UIColor purpleColor]]; 
Смежные вопросы