Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change UITabBarItem Badge position?

This is how my Tabbar is looking right now.

enter image description here

How do I move that badge so that it overlaps the top right of the bell icon? Any help is appreciated.

like image 905
Drunken Daddy Avatar asked Aug 16 '16 10:08

Drunken Daddy


1 Answers

try this:

func repositionBadge(tabIndex: Int){

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

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

pay attention, tabIndex starts from 1

like image 91
Marco Santarossa Avatar answered Oct 12 '22 13:10

Marco Santarossa