简体   繁体   中英

iOS Custom Tab Bar Items Taller Than Tab Bar

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

Ok, so, I'm trying to create a custom tab bar. I've read a hundred tutorials and downloaded half as many sample code projects and this problem seems to still be in all of them.

I don't really want a custom background, what I really want to for the buttons to take up the entire area so that no background ever shows. Why is it that when using an image sized at 49px (98px for Retina) for the background AND the buttons...the tab bar itself is scaled up and that ugly glow that Apple adds is viewable?

Here's the code I used (found here on 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];

Again, I can remove that background image as it's of no use to me, but without it, the default black background for the tab bar is viewable. Both bad. Help.Please.

Well, I can help you with the glow. To hide it just create a transparent image and use it instead.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM