Error[8]: Undefined offset: 1, File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 121
File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 473, decode(

概述是否可以更改从 Xcode构建的Objective-C iPhone应用程序的标签栏徽章颜色?它总是红色的.任何人都可以指示我解决它吗? 谢谢 对于使用 Swift的人: extension UITabBarController { func setBadges(badgeValues: [Int]) { for view in self.tabBar.subviews { 是否可以更改从 Xcode构建的Objective-C iPhone应用程序的标签栏徽章颜色?它总是红色的.任何人都可以指示我解决它吗?

谢谢

解决方法 对于使用 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徽章颜色所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

)
File: /www/wwwroot/outofmemory.cn/tmp/route_read.php, Line: 126, InsideLink()
File: /www/wwwroot/outofmemory.cn/tmp/index.inc.php, Line: 165, include(/www/wwwroot/outofmemory.cn/tmp/route_read.php)
File: /www/wwwroot/outofmemory.cn/index.php, Line: 30, include(/www/wwwroot/outofmemory.cn/tmp/index.inc.php)
ios – 更改UITabBar徽章颜色_app_内存溢出

ios – 更改UITabBar徽章颜色

ios – 更改UITabBar徽章颜色,第1张

概述是否可以更改从 Xcode构建的Objective-C iPhone应用程序的标签栏徽章颜色?它总是红色的.任何人都可以指示我解决它吗? 谢谢 对于使用 Swift的人: extension UITabBarController { func setBadges(badgeValues: [Int]) { for view in self.tabBar.subviews { 是否可以更改从 Xcode构建的Objective-C iPhone应用程序的标签栏徽章颜色?它总是红色的.任何人都可以指示我解决它吗?

谢谢

解决方法 对于使用 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徽章颜色所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1014170.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-22
下一篇 2022-05-22

发表评论

登录后才能评论

评论列表(0条)

保存