iOS 7 : UITabBarItem badge z-index

标签 ios objective-c uitabbar badge

我想在 selectionIndicatorImage 上方显示一个 UITabBarItem 角标(Badge)。有3张截图:

截图

enter image description here

浅灰色是 selectionIndicatorImage。是的,角标(Badge)看起来不错。当我在云图标 UITabBar 内部触摸时,变成:

enter image description here

这是错误的..我想在选择图像上方显示角标(Badge)。 如果 UITabBar 没有图标 - 它看起来不错。

enter image description here

我该如何解决这个问题? 提前致谢。

已编辑

我在 Storyboard中添加图标。对于角标(Badge),我编写了代码:

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

用于选择IndicatorImage

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

最佳答案

我知道这有点棘手,但我认为 Apple 没有以正确的顺序添加 TabBar subview 。 无论如何,我已经通过以下方式修复了它

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 badge z-index,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21472960/

相关文章:

ios - 在启动画面中使用 AdMob

ios - 具有自动布局和 UITableAutomaticDimension 的动态高度表单元格(动态 UILabel + 几个 UIImageViews)

objective-c - 向下滚动后表格 View 单元格正在更改

ios - UIWebView 在加载 PDF 文件时没有释放内存

ios - 是否允许继承TWTweetCompose ViewController?我在 ios 6.0 上发生崩溃

ios - 用户输入时如何检查文本字段输入字符串

iphone - 如何移动 UITabBarItem 的标题?

ios - UITabBarController 的默认背景颜色是什么?

iphone - 选择 UITabBar 时调用方法?

ios - 在 iOS 中的图像之间左右滚动