2016-08-16 100 views
3

这就是我的Tabbar现在的样子。如何更改UITabBarItem徽章位置?

enter image description here

如何移动该徽章,使其重叠铃图标右上方?任何帮助表示赞赏。

+0

看到这个http://stackoverflow.com/questions/24236823/how-to-adjust-tab-bar-badge-位置 –

+0

[iOS 7 UITabBar徽章位置]的可能重复(http://stackoverflow.com/questions/19165671/ios-7-uitabbar-badge-position) – chrs

回答

5

试试这个:

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

注意,开始的tabIndex从1

+2

请注意:这使用私有API,Apple可能会拒绝您的应用程序使用这个。 – Louis