【发布时间】:2013-09-16 05:35:13
【问题描述】:
我有一个自定义的 UITabBar 并在 AppDelegate 中使用以下代码:
- (void)tabBarController:(MainUITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
[self customizeTabBar];
}
- (void)customizeTabBar {
NSLog(@"*******customizeTabBar*******");
UIImage *tabBackground = [[UIImage imageNamed:@"unselectedtab"]
resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
// Set background for all UITabBars
[[UITabBar appearance] setBackgroundImage:tabBackground];
// Set tint color for the images for all tabbars
[[UITabBar appearance] setSelectedImageTintColor:[UIColor whiteColor]];
// Set selectionIndicatorImage for all tabbars
[[UITabBar appearance] setSelectionIndicatorImage:[UIImage imageNamed:@"selectedtab"]];
}
- (void)tabBarController:(MainUITabBarController *)tabBarController didEndCustomizingViewControllers:(NSArray *)viewControllers changed:(BOOL)changed
{
NSLog(@"*******didEndCustomizingViewControllers*******");
}
这在 iOS5+ 中一切正常,但在 7 中,第一次加载第一个 TabBarItem 时,项目指示器为白色,并且按钮似乎已被选中,但未加载“selectedTab”图像。
当我按下另一个选项卡时,新选项卡为红色并且显示正确 - 就像第一个或之后选择的任何选项卡栏项目一样 - 它仅在首次启动时不起作用。
customizeTabBar 被调用,但所选图像未在首次启动时出现。
didEndCustomizingViewControllers 似乎根本没有被调用。
这在 iOS7 上的模拟器或设备中不起作用 - 但在 iOS5、6 上有效。
有什么想法吗? 提前致谢。
【问题讨论】: