iOS 7: UITabBarItem badge z-index

不羁岁月 提交于 2019-12-05 03:59:46

I know it's a bit tricky, but I think Apple didn't add TabBar subview in correct order. anyway I've fixed it the following way

for (UIView *subview in marketTrackerAppDelegate.tabBarController.tabBar.subviews)
{
    if ([marketTrackerAppDelegate.tabBarController.neededController.tabBarItem respondsToSelector:@selector(view)] &&
        [marketTrackerAppDelegate.tabBarController.neededController.tabBarItem performSelector:@selector(view)] == subview)
    {
        [marketTrackerAppDelegate.tabBarController.tabBar bringSubviewToFront:subview];
        break;
    }
}

I had the same issue. You can fix it with code that @dollar8 suggested or change order of UITabBarItems creation.

I have 4th tab with badge and SelectionIndicatorImage of 5th tab overlay badge of 4th tab, so first I set 5th tab:

UIImage *item5image = [UIImage imageNamed:@"profile_tabbar_item"];
UIImage *item5imageSel = [UIImage imageNamed:@"profile_tabbar_item_selected"];
item5image = [item5image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
item5imageSel = [item5imageSel imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
tab5.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"" image:item5image selectedImage:item5imageSel];

and after set 4th tab:

UIImage *item4image = [UIImage imageNamed:@"messages_tabbar_item"];
UIImage *item4imageSel = [UIImage imageNamed:@"messages_tabbar_item_selected"];
item4image = [item4image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
item4imageSel = [item4imageSel imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
tab4.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"" image:item4image selectedImage:item4imageSel];

And the order of subview will be right. When I set 4th tab before 5th tab - the SelectionIndicatorImage overlay badge view.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!