Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS 7: UITabBarItem badge z-index

I'd like to show a UITabBarItem badge above the selectionIndicatorImage. There are 3 screenshots:

Screenshots

enter image description here

Light gray color is the selectionIndicatorImage. Yes, badge looks good. When I touch up inside at the cloud icon UITabBar become:

enter image description here

It's wrong.. I'd like to show badge above the selection image. If there is no icon for UITabBar - it looks good.

enter image description here

How can I fix this issue? Thanks in advance.

Edited

I add icons in the storyboard. For badge I've made the code:

UITabBarItem *cartTabBarItem = (UITabBarItem *)[self.tabBarController.tabBar.items objectAtIndex:3];
if ([[DataSourceWrapper getInstance] getFullCost] == 0)
         cartTabBarItem.badgeValue = nil;
    else
        cartTabBarItem.badgeValue = [NSString stringWithFormat:@"%.0f тнг", [[DataSourceWrapper getInstance] getFullCost]];

For selectionIndicatorImage

[[UITabBar appearance] setSelectionIndicatorImage:[UIImage imageNamed:@"selected-tabbar-bg.png"]];
like image 931
Artem Z. Avatar asked Jan 31 '14 05:01

Artem Z.


1 Answers

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;
    }
}
like image 110
dollar2048 Avatar answered Oct 17 '22 04:10

dollar2048