本文主要是介绍给 tabBarItem 添加小红点,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
//MARK: - 添加小红点func showDotOnItemIndex(index:Int) {self.removeBadgeOnItemIndex(index: 2)let appDelegate = UIApplication.shared.delegate as! AppDelegateif(appDelegate.window!.rootViewController!.isKind(of: UITabBarController.self)){let rootVc = appDelegate.window!.rootViewController as! UITabBarControllerlet tabBar = rootVc.tabBarlet view = UIView()view.tag = 888 + indexview.layer.cornerRadius = 3view.backgroundColor = UIColor.redlet tabBarFrame = tabBar.framelet percentX = (Double(index) + 0.6) / 4let x = ceilf(Float( percentX) * Float((tabBarFrame.size.width)))let y = ceilf(0.01 * Float((tabBarFrame.size.width)))view.frame = CGRect(x:CGFloat(x), y:CGFloat(y), width:6, height:6)tabBar.addSubview(view)}
这篇关于给 tabBarItem 添加小红点的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!