我正在尝试使用所选和未选中状态的图像创建自定义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];
此图像显示问题,红色是间隙:
编辑以添加代码以创建UITabbar
self.tabBarController = [[BaseTabbarController alloc] init];
self.tabBarController.delegate = self;
self.tabBarController.viewControllers = @[navControll1, navControll2, navControll3, navControll4, navControll5];
self.window.rootViewController = self.tabBarController;
我感谢你们提供的任何帮助
答案 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);