How to adjust tab bar badge position?

前端 未结 6 1900
鱼传尺愫
鱼传尺愫 2021-01-12 07:57

I\'m displaying badge on tab bar but when number increase it goes out to tab bar item like shown in image

\"this

6条回答
  •  一个人的身影
    2021-01-12 08:05

    I found Kateryna's answer to be useful in putting me on the right track, but I had to update it a little:

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

    Please note the tab integer is NOT zero-indexed, so the first tab will be number 1, the 2nd number 2, etc.

提交回复
热议问题