简体   繁体   中英

ios7 - Custom UItabbar has a gap in the bottom

Im trying to create a custom UITabbar using images for the selected and unselected states.

this is my code:

if ([UIImage instancesRespondToSelector:@selector(imageWithRenderingMode:)]) {

    tab_01_on_image = [[UIImage imageNamed:@"Tabbar_on_01"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    tab_01_off_image = [[UIImage imageNamed:@"Tabbar_off_01"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

} else {
    tab_01_on_image = [UIImage imageNamed:@"Tabbar_on_01"] ;
    tab_01_off_image = [UIImage imageNamed:N@"Tabbar_off_01"] ;

}

[[[self.tabBarController.tabBar items] objectAtIndex:index] setFinishedSelectedImage:tab_01_on_image withFinishedUnselectedImage:tab_01_off_image];

This image shows the problem, the red color is the gap:

在此输入图像描述

EDIT to add the code to create the UITabbar

self.tabBarController = [[BaseTabbarController alloc] init];
self.tabBarController.delegate = self;
self.tabBarController.viewControllers = @[navControll1, navControll2, navControll3, navControll4, navControll5];
self.window.rootViewController = self.tabBarController;

I appreciate any help you guys can offer

I finally found the solution. Changing the imageInsets of each tabbarItem did the trick.

tabBarItem1.imageInsets = UIEdgeInsetsMake(6, 0, -6, 0);
tabBarItem2.imageInsets = UIEdgeInsetsMake(6, 0, -6, 0);
tabBarItem3.imageInsets = UIEdgeInsetsMake(6, 0, -6, 0);
tabBarItem4.imageInsets = UIEdgeInsetsMake(6, 0, -6, 0);
tabBarItem5.imageInsets = UIEdgeInsetsMake(6, 0, -6, 0);

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