ios7 - Custom UItabbar has a gap in the bottom-阿里云开发者社区

开发者社区> 云计算> 正文

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:

enter image description here

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

how high Tabbar_on_01? –  Ilario Nov 15 at 12:37
the @2x image is 128x100px I also tried with 128x98px and got the same problem. –  FelipeOliveira Nov 15 at 12:47 
Is your view designed with Interface Builder, or do you create it programmatically? –  zbMax Nov 15 at 13:27
programmatically zbMax –  FelipeOliveira Nov 15 at 13:39
Can you edit your question and add the code creating the tabbar please? By the way, follow this guidelines page for your icon dimension :… –  zbMaxNov 15 at 13:53
add / show 1 more comment
  start a bounty

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);
欢迎加群互相学习,共同进步。QQ群:iOS: 58099570 | Android: 330987132 | Go:217696290 | Python:336880185 | 做人要厚道,转载请注明出处!


+ 订阅

时时分享云计算技术内容,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。