使用自定义标签栏图像和没有标签栏标题的插图时如何调整标签栏徽章位置?

How to adjust Tab bar badge position when using custom tab bar image and inset without tab bar title?

我无法将徽章重新定位到通常应有的默认位置。我已经尝试过此解决方案和其他一些解决方案,但 none 有效。 How to adjust tab bar badge position?

我的问题可能与标签栏图像有关,而不是徽章位置。我在标签栏图像大小、插图等方面玩了很多,但 none 似乎有效。

有谁知道如何修复它?

func repositionBadge(tab: Int){

   for badgeView in self.tabBarController!.tabBar.subviews[tab].subviews {

       if NSStringFromClass(badgeView.classForCoder) == "_UIBadgeView" {
          badgeView.layer.transform = CATransform3DIdentity
          badgeView.layer.transform = CATransform3DMakeTranslation(-17.0,   1.0, 1.0)
        }
    }

}

请注意制表符整数不是从零开始索引的,因此第一个制表符将为数字 1,第二个为数字 2,依此类推。