2

我现在已经挣扎了几个小时,试图为我的 UITabBar 中的每个项目添加一个 uniqe 图像(因为我希望标签分隔符正确显示,并且在最左边和最右边没有分隔符)。

我的应用程序委托中的以下代码在底部以一种奇怪的方式显示项目。也想删除标题标签。什么是正确的方法?这真让我抓狂..

我的标签栏的图像

UIImage *selectedImage0   = [UIImage imageNamed:@"home-tab-active"];
UIImage *unselectedImage0 = [UIImage imageNamed:@"home-tab"];

UIImage *selectedImage1   = [UIImage imageNamed:@"guide-tab-active"];
UIImage *unselectedImage1 = [UIImage imageNamed:@"guide-tab"];

UIImage *selectedImage2   = [UIImage imageNamed:@"search-tab-active"];
UIImage *unselectedImage2 = [UIImage imageNamed:@"search-tab"];

UIImage *selectedImage3   = [UIImage imageNamed:@"favorites-tab-active"];
UIImage *unselectedImage3 = [UIImage imageNamed:@"favorites-tab"];

UIImage *selectedImage4   = [UIImage imageNamed:@"locations-tab-active"];
UIImage *unselectedImage4 = [UIImage imageNamed:@"locations-tab"];

// The Tab Bar
UITabBarController *tabBarController = (UITabBarController *)self.window.rootViewController;
UITabBarItem *item0 = [tabBarController.tabBar.items objectAtIndex:0];
UITabBarItem *item1 = [tabBarController.tabBar.items objectAtIndex:1];
UITabBarItem *item2 = [tabBarController.tabBar.items objectAtIndex:2];
UITabBarItem *item3 = [tabBarController.tabBar.items objectAtIndex:3];
UITabBarItem *item4 = [tabBarController.tabBar.items objectAtIndex:4];

[item0 setFinishedSelectedImage:selectedImage0 withFinishedUnselectedImage:unselectedImage0];
[item1 setFinishedSelectedImage:selectedImage1 withFinishedUnselectedImage:unselectedImage1];
[item2 setFinishedSelectedImage:selectedImage2 withFinishedUnselectedImage:unselectedImage2];
[item3 setFinishedSelectedImage:selectedImage3 withFinishedUnselectedImage:unselectedImage3];
[item4 setFinishedSelectedImage:selectedImage4 withFinishedUnselectedImage:unselectedImage4];
4

1 回答 1

0

标签项的标题和图像应该来自分配给每个标签的内容控制器,而不是来自标签栏控制器。看起来你有你在应用程序委托中创建的那些以及属于各个控制器的那些,这就是为什么你会得到重叠的图像和标题(标签栏项目的默认字符串是标题分配给该选项卡的控制器)。

于 2013-01-15T00:30:33.743 回答