如何在Xcode中更改选项卡栏颜色 [英] How To Change Tab bar color in Xcode
本文介绍了如何在Xcode中更改选项卡栏颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何更改此代码中的标签栏颜色?我的标签栏是黑色的。点击将其更改为蓝色。我想将拖曳颜色更改为任何其他颜色。
How do I go about changing the tab bar color in this code? My tab bar is black. On click changes it to blue. I want to change the tow color to any other color.
此代码来自于:application.m
并且包含:rotatingTabBarController.m,rotatingTabBarController.h
This code is from :application.m and there :rotatingTabBarController.m ,rotatingTabBarController.h
// 1B) If this app uses tabs, create a tabbed navigation application and set the default screen for each tab
// to the defaultScreenGuid in the tabs data
if([self.tabs count] > 0){
[BT_debugger showIt:self:[NSString stringWithFormat:@"building a tabbed based navigation app%@", @""]];
if([self.screens count] > 0){
//appDelegate
qoqb_appDelegate *appDelegate = (qoqb_appDelegate *)[[UIApplication sharedApplication] delegate];
//initialize the tab bar controller
rootTabBarController = [[BT_rotatingTabBarController alloc] init];
[rootTabBarController.view setFrame:[[UIScreen mainScreen] bounds]];
[rootTabBarController setDelegate:appDelegate];
rootTabBarController.view.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
//if we have a tabbar color setup in the theme
if(self.rootTheme != nil){
if([self.rootTheme.jsonVars objectForKey:@"tabBarColor"]){
if([[self.rootTheme.jsonVars objectForKey:@"tabBarColor"] length] > 3){
UIColor *tabberColor = [BT_color getColorFromHexString:[self.rootTheme.jsonVars objectForKey:@"tabBarColor"]];
NSString *tabberOpacity = @".50";
if([self.rootTheme.jsonVars objectForKey:@"tabBarColorOpacity"]){
if([[self.rootTheme.jsonVars objectForKey:@"tabBarColorOpacity"] length] > 0){
tabberOpacity = [NSString stringWithFormat:@".%@", [self.rootTheme.jsonVars objectForKey:@"tabBarColorOpacity"]];
if([tabberOpacity isEqualToString:@".100"]) tabberOpacity = @".50";
}
//colorize the tab-bar
[rootTabBarController addTabColor:tabberColor:[tabberOpacity doubleValue]];
}
}
}
}
//Fill a temporary array of view controllers to assign to tab bar controller
NSMutableArray *tmpViewControllers = [[NSMutableArray alloc] init];
//loop through each tab bar item in application data
for(int i = 0; i < [[self tabs] count]; i++){
//this tab
BT_item *thisTab = (BT_item *)[[self tabs] objectAtIndex:i];
NSString *textLabel = [[thisTab jsonVars] objectForKey:@"textLabel"];
UIImage *tabIcon = [UIImage imageNamed:[[thisTab jsonVars] objectForKey:@"iconName"]];
//get the screen from the apps array of screens for this tab's view controller
if([[thisTab jsonVars] objectForKey:@"homeScreenItemId"]){
BT_item *thisTabsDefaultScreenData = [self getScreenDataByItemId:[[thisTab jsonVars] objectForKey:@"homeScreenItemId"]];
//if this is the first tab in the list, remember it as the "currently loaded screen", also make it the "previously loaded screen"
if(i == 0){
[self setCurrentScreenData:thisTabsDefaultScreenData];
[self setPreviousScreenData:thisTabsDefaultScreenData];
[thisTabsDefaultScreenData setIsHomeScreen:TRUE];
//if theScreen has an audio file..load it in the delegate
if([[BT_strings getJsonPropertyValue:thisTabsDefaultScreenData.jsonVars:@"audioFileName":@""] length] > 3){
//appDelegate
qoqb_appDelegate *appDelegate = (qoqb_appDelegate *)[[UIApplication sharedApplication] delegate];
//initialize audio in different thread to prevent UI blocking
[NSThread detachNewThreadSelector: @selector(loadAudioForScreen:) toTarget:appDelegate withObject:thisTabsDefaultScreenData];
}
}
推荐答案
tabBar.tintColor = [UIColor greenColor];
将会崩溃看到docs
一种更安全的方法是:
if ([tabBarController.tabBar respondsToSelector:@selector(setTintColor:)]) {
[tabBarController.tabBar setTintColor:color];
}
//新代码
if ([rootTabBarController.tabBar respondsToSelector:@selector(setTintColor:)]) {
[rootTabBarController.tabBar setTintColor:tabberColor];
}
这篇关于如何在Xcode中更改选项卡栏颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文