ios7 - 自定义UItabbar底部有一个空白

时间:2013-11-15 12:19:21

标签: ios iphone ios7 uitabbarcontroller uitabbar

我正在尝试使用所选和未选中状态的图像创建自定义UITabbar。

这是我的代码:

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

此图像显示问题,红色是间隙:

enter image description here

编辑以添加代码以创建UITabbar

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

我感谢你们提供的任何帮助

1 个答案:

答案 0 :(得分:6)

我终于找到了解决方案。更改每个tabbarItem的imageInsets就可以了。

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