How to adjust tab bar badge position?

Blios picture Blios · Jun 16, 2014 · Viewed 9.4k times · Source

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

this image

I want to move the badge view slightly left so it fit on selected tab image.i tried as described here but no luck. So is there is any way to adjust badge view position?Any help would be appreciated.

Answer

Amir picture Amir · Nov 6, 2015

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.