好的,所以,我正在尝试创建一个自定义标签栏。我已经阅读了一百篇教程并下载了一半的示例代码项目,而且这个问题似乎仍然存在于所有这些项目中。
我真的不想要一个自定义背景,我真正想要的是按钮占据整个区域,这样就不会显示任何背景。为什么当使用大小为 49 像素(Retina 为 98 像素)的图像作为背景和按钮时……标签栏本身被放大了,而苹果添加的丑陋的光芒是可见的?
这是我使用的代码(在 Stack 上找到):
UIImage *selectedImage0 = [UIImage imageNamed:@"transactions_tab_btn_active"];
UIImage *unselectedImage0 = [UIImage imageNamed:@"transactions_tab_btn"];
UIImage *selectedImage1 = [UIImage imageNamed:@"bills_tab_btn_active"];
UIImage *unselectedImage1 = [UIImage imageNamed:@"bills_tab_btn"];
UIImage *selectedImage2 = [UIImage imageNamed:@"messages_tab_btn_active"];
UIImage *unselectedImage2 = [UIImage imageNamed:@"messages_tab_btn"];
UIImage *selectedImage3 = [UIImage imageNamed:@"reports_tab_btn_active"];
UIImage *unselectedImage3 = [UIImage imageNamed:@"reports_tab_btn"];
UITabBar *tabBar = self.tabBarController.tabBar;
UITabBarItem *item0 = [tabBar.items objectAtIndex:0];
UITabBarItem *item1 = [tabBar.items objectAtIndex:1];
UITabBarItem *item2 = [tabBar.items objectAtIndex:2];
UITabBarItem *item3 = [tabBar.items objectAtIndex:3];
UIImageView *tabBarImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"tab_bar"]];
if ([[[UIDevice currentDevice] systemVersion] floatValue] < 5) {
[tabBar insertSubview:tabBarImageView atIndex:0];
}else{
[tabBar insertSubview:tabBarImageView atIndex:1];
}
[item0 setFinishedSelectedImage:selectedImage0 withFinishedUnselectedImage:unselectedImage0];
[item1 setFinishedSelectedImage:selectedImage1 withFinishedUnselectedImage:unselectedImage1];
[item2 setFinishedSelectedImage:selectedImage2 withFinishedUnselectedImage:unselectedImage2];
[item3 setFinishedSelectedImage:selectedImage3 withFinishedUnselectedImage:unselectedImage3];
同样,我可以删除该背景图像,因为它对我没有用,但没有它,标签栏的默认黑色背景是可见的。都不好。请帮忙。