谢谢
解决方法 对于使用 Swift的人:extension UITabbarController { func setBadges(badgeValues: [Int]) { for vIEw in self.tabbar.subvIEws { if vIEw is CustomTabBadge { vIEw.removeFromSupervIEw() } } for index in 0...badgeValues.count-1 { if badgeValues[index] != 0 { addBadge(index,value: badgeValues[index],color:UIcolor(paletteItem: .Accent),Font: UIFont(name: Constants.themeApp.regularFontname,size: 11)!) } } } func addBadge(index: Int,value: Int,color: UIcolor,Font: UIFont) { let badgeVIEw = CustomTabBadge() badgeVIEw.clipsToBounds = true badgeVIEw.textcolor = UIcolor.whitecolor() badgeVIEw.textAlignment = .Center badgeVIEw.Font = Font badgeVIEw.text = String(value) badgeVIEw.backgroundcolor = color badgeVIEw.tag = index tabbar.addSubvIEw(badgeVIEw) self.positionBadges() } overrIDe public func vIEwDIDLayoutSubvIEws() { super.vIEwDIDLayoutSubvIEws() self.tabbar.setNeedsLayout() self.tabbar.layoutIfNeeded() self.positionBadges() } // positioning func positionBadges() { var tabbarbuttons = self.tabbar.subvIEws.filter { (vIEw: UIVIEw) -> Bool in return vIEw.userInteractionEnabled // only UITabbarbutton are userInteractionEnabled } tabbarbuttons = tabbarbuttons.sort({ .frame.origin.x < .frame.origin.x }) for vIEw in self.tabbar.subvIEws { if vIEw is CustomTabBadge { let badgeVIEw = vIEw as! CustomTabBadge self.positionBadge(badgeVIEw,items:tabbarbuttons,index: badgeVIEw.tag) } } } func positionBadge(badgeVIEw: UIVIEw,items: [UIVIEw],index: Int) { let itemVIEw = items[index] let center = itemVIEw.center let xOffset: CGfloat = 12 let yOffset: CGfloat = -14 badgeVIEw.frame.size = CGSizeMake(17,17) badgeVIEw.center = CGPointMake(center.x + xOffset,center.y + yOffset) badgeVIEw.layer.cornerRadius = badgeVIEw.bounds.wIDth/2 tabbar.bringSubvIEwToFront(badgeVIEw) }}class CustomTabBadge: UILabel {}总结
以上是内存溢出为你收集整理的ios – 更改UITabBar徽章颜色全部内容,希望文章能够帮你解决ios – 更改UITabBar徽章颜色所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)