2013-11-15 9 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

を作成するためのコードを追加するEDIT
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); 
関連する問題