给 tabBarItem 添加小红点

本文介绍了如何在iOS应用中为TabBarItem添加和移除小红点指示器。通过自定义UIView并设置其frame和背景颜色,可以实现小红点的显示,同时提供了移除小红点的方法。
摘要由CSDN通过智能技术生成
//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)
        }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值