iOS自定义标签栏项目比标签栏更高

时间:2012-12-10 17:42:19

标签: ios ios5 ios6 uitabbar uitabbaritem

Custom tab bar items are taller than the tab bar

好的,我正在尝试创建一个自定义标签栏。我已经阅读了一百个教程并下载了一半的示例代码项目,这个问题似乎仍然存在于所有这些项目中。

我真的不想要一个自定义背景,我真正希望按钮占据整个区域,以便没有任何背景显示。为什么当使用尺寸为49px(Retina为98px)的图像作为背景和按钮时...标签栏本身是按比例放大的,而Apple添加的丑陋发光是可见的?

这是我使用的代码(在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];

同样,我可以删除那个背景图片,因为它对我没用,但没有它,标签栏的默认黑色背景是可见的。两个都不好。 Help.Please。

1 个答案:

答案 0 :(得分:0)

好吧,我可以帮助你发光。要隐藏它,只需创建一个透明图像并使用它。

UIImage* image = [UIImage imageNamed:@"transparent.png"];
[[UITabBar appearance] setSelectionIndicatorImage:image];