iOS 7:UITabBarItem徽章z-index [英] iOS 7: UITabBarItem badge z-index

查看:196
本文介绍了iOS 7:UITabBarItem徽章z-index的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 selectionIndicatorImage 上方显示 UITabBarItem 徽章。有3个截图:

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

浅灰色是 selectionIndicatorImage 。是的,徽章看起来不错。当我在云端图标中触摸 UITabBar 变为:

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

这是错误的..我想在选择图片上方显示徽章。
如果 UITabBar 没有图标 - 看起来不错。

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

如何解决此问题?
提前致谢。

How can I fix this issue? Thanks in advance.

我在故事板中添加了图标。对于徽章,我已经制作了代码:

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]];

对于selectionIndicatorImage

For selectionIndicatorImage

[[UITabBar appearance] setSelectionIndicatorImage:[UIImage imageNamed:@"selected-tabbar-bg.png"]];


推荐答案

我知道这有点棘手,但我认为Apple没有按正确的顺序添加TabBar子视图。
无论如何我已按以下方式修复它

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;
    }
}

这篇关于iOS 7:UITabBarItem徽章z-index的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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