2013-11-15 64 views
5

我試圖創建一個自定義的UITabbar使用圖像的選定和未選中狀態。ios7 - 自定義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:[email protected]"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; 

我感謝你們提供的任何幫助

+0

Tabbar_on_01有多高? – Ilario

+0

@ 2x圖像是128x100px 我也嘗試過128x98px並得到了同樣的問題。 – FelipeOliveira

+0

您的視圖是使用Interface Builder設計的,還是以編程方式創建它? – zbMax

回答

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