我有一个UITabBar,在升级到Xcode 7之前正常运行,但现在我找不出问题所在。我尝试了几种解决方案,包括为我创建的每个选项卡设置imageWithRenderingMode,尝试更改UITabBar的背景颜色以查看是否仅仅是选项卡是白色的,以及将图标本身更新为新版本。我的默认选中选项卡完全正常显示,当我选择另一个选项卡时,文本会显示出来,但是没有图像。(文本也会保持,并且在移动到另一个选项卡时更改为默认的灰色。)
以下是我目前实现选项卡栏的方式。 创建选项卡栏的函数:
以下是我目前实现选项卡栏的方式。 创建选项卡栏的函数:
void MakeTabBar(id target)
{
PFUser *currentUser = [PFUser currentUser];
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
appDelegate.recentView = [[RecentView alloc] init];
appDelegate.groupsView = [[GroupsView alloc] init];
appDelegate.settingsView = [[SettingsView alloc] init];
appDelegate.homeView = [[HomeView alloc] init];
NavigationController *navController1 = [[NavigationController alloc] initWithRootViewController:appDelegate.recentView];
NavigationController *navController2 = [[NavigationController alloc] initWithRootViewController:appDelegate.groupsView];
NavigationController *navController4 = [[NavigationController alloc] initWithRootViewController:appDelegate.settingsView];
NavigationController *navController5 = [[NavigationController alloc] initWithRootViewController:appDelegate.homeView];
appDelegate.tabBarController = [[UITabBarController alloc] init];
appDelegate.tabBarController.tabBar.translucent = NO;
appDelegate.tabBarController.selectedIndex = DEFAULT_TAB;
[[UITabBar appearance] setTintColor:COLOR_OUTGOING];
NSMutableDictionary *customAttributes = [NSMutableDictionary dictionary];
BOOL isAdmin = [currentUser[@"isAdmin"] boolValue];
if(isAdmin){
[customAttributes setObject:currentUser[@"isAdmin"] forKey:@"isAdmin"];
appDelegate.peopleView = [[PeopleView alloc] init];
NavigationController *navController3 = [[NavigationController alloc] initWithRootViewController:appDelegate.peopleView];
appDelegate.tabBarController.viewControllers = @[navController5, navController1, navController2, navController3, navController4];
} else{
appDelegate.tabBarController.viewControllers = @[navController5, navController1, navController2, navController4];
}
BOOL isTester = [currentUser[@"isTestData"] boolValue];
if(isTester){
[customAttributes setObject:currentUser[@"isTestData"] forKey:@"isTestData"];
}
[appDelegate.window setRootViewController:appDelegate.tabBarController];
}
在每个视图中编写代码以创建选项卡:
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
{
[self.tabBarItem setImage:[UIImage imageNamed:@"tab_consultants"]];
self.tabBarItem.title = @"Consultants";
}
return self;
}