gpt4 book ai didi

ios - 为每个标签栏项目设置背景

转载 作者:行者123 更新时间:2023-12-01 16:52:46 24 4
gpt4 key购买 nike

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

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

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

最佳答案

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

关于ios - 为每个标签栏项目设置背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14328345/

24 4 0