//MARK: - 添加小红点
func showDotOnItemIndex(index:Int) {
self.removeBadgeOnItemIndex(index: 2)
let appDelegate = UIApplication.shared.delegate as! AppDelegate
if(appDelegate.window!.rootViewController!.isKind(of: UITabBarController.self)){
let rootVc = appDelegate.window!.rootViewController as! UITabBarController
let tabBar = rootVc.tabBar
let view = UIView()
view.tag = 888 + index
view.layer.cornerRadius = 3
view.backgroundColor = UIColor.red
let tabBarFrame = tabBar.frame
let percentX = (Double(index) + 0.6) / 4
let 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 添加小红点
最新推荐文章于 2020-11-22 20:53:24 发布
本文介绍了如何在iOS应用中为TabBarItem添加和移除小红点指示器。通过自定义UIView并设置其frame和背景颜色,可以实现小红点的显示,同时提供了移除小红点的方法。
摘要由CSDN通过智能技术生成