设置每个标签栏项目的背景

时间:2013-01-14 22:57:41

标签: ios xcode background uitabbar

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

我在app appate中的以下代码在底部以奇怪的方式显示项目..也想要删除标题标签。什么是正确的方法?这让我抓狂......

Image of my tabbar

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];

1 个答案:

答案 0 :(得分:0)

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