我通过UITabBar外观将SelectionIndicatorImage设置为可伸缩图像(以适应各种设备宽度):
UIImage *selectedImage = [[UIImage imageNamed:@"SelectedTab"] stretchableImageWithLeftCapWidth:0 topCapHeight:0];
[[UITabBar appearance] setSelectionIndicatorImage:selectedImage];
结果我在屏幕边缘上得到了一个2pt填充。我基本上试图使用选择指标作为当前所选UITabBarItem的背景。
http://i.stack.imgur.com/qFHEk.png
解决这个问题的简单方法是什么?
答案 0 :(得分:1)
如果你想在你的应用程序中使用带有选择和取消选择功能的UITabBarController,那么你应该这个代码
[[self.tabBarController tabBar] setBackgroundImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"bg_tabBar" ofType:@"png"]]];
[[self.tabBarController tabBar] setSelectionIndicatorImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"bg_tabItem_selected" ofType:@"png"]]];
NSArray *arrTabItems = [[self.tabBarController tabBar] items];
UITabBarItem *tabBarItem = [arrTabItems objectAtIndex:0];
[tabBarItem setFinishedSelectedImage:[UIImage imageNamed:@"img_selected.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"img_unselected.png"]];
[tabBarItem setImageInsets:UIEdgeInsetsMake(5, 5, 0, 5)];