UITabBar外观setSelectionIndicatorImage在第一次启动iOS7时不起作用 [英] UITabBar appearance setSelectionIndicatorImage does not work on first launch iOS7

查看:110
本文介绍了UITabBar外观setSelectionIndicatorImage在第一次启动iOS7时不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个自定义的UITabBar并在AppDelegate中使用以下代码:

I have a customised UITabBar and use the following code in the 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 +中都很好,但在第一次加载第一个TabBarItem时为7项目指示器为白色,似乎已选择按钮,但未加载selectedTab图像。

This is all fine in iOS5+ but in 7 on first load the first TabBarItem the item indicator is white and the button seems to have been selected but the "selectedTab" image is not loaded.

当我按下另一个标签时,新标签为红色并正确显示 - 与此后选择的第一个或任何标签栏项目一样 - 它仅在首次启动时不起作用。

When I press another tab the new tab is red and appears correctly - as does the first or any tab bar item selected after this - it only doesn't work on first launch.

customizeTabBar被调用但所选图像不会出现在第一次启动。

customizeTabBar get called but the selected image does not appear on first launch.

didEndCustomizingViewControllers似乎根本没有被调用。

didEndCustomizingViewControllers does not seem to get called at all.

这在模拟器中不起作用或iOS7上的设备 - 但在iOS5,6上。

This doesn't work in emulator or device on iOS7 - but does on iOS5, 6.

任何想法?
提前致谢。

Any ideas? Thanks in advance.

推荐答案

再次设置标签栏的选择指标图像,除此之外通过外观,为我工作!

Setting the selection indicator image for the tab bar directly once again, apart from doing it via appearance, worked for me!

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    ....

    UITabBarController *tabBarContr = (UITabBarController *)self.window.rootViewController;
    ...
    [[UITabBar appearance] setSelectionIndicatorImage:[UIImage imageNamed:@"tab_bar_selection_indicator.png"]];

    // iOS7 hack: to make selectionIndicatorImage appear on the selected tab on the first app run
    [[tabBarContr tabBar] setSelectionIndicatorImage:[UIImage imageNamed:@"tab_bar_selection_indicator.png"]];

    return YES;
}

这篇关于UITabBar外观setSelectionIndicatorImage在第一次启动iOS7时不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆