• Swift中给UIView添加Badge


    extension UIView{
          //任意UIView添加badge
        func showBadgeValue(#strBadgeValue: String) -> Void{
           
            let tabBar = UITabBar(frame: CGRectMake(0, 0, 320, 50))
            let item = UITabBarItem(title: "", image: nil, tag: 0)
            item.badgeValue = strBadgeValue
            let array = [item]
           
            tabBar.items = array
            for viewTab in tabBar.subviews{
                for subview in viewTab.subviews{
                    let strClassName = String(UTF8String: object_getClassName(subview))
                    if strClassName == "UITabBarButtonBadge" || strClassName == "_UIBadgeView"{
                        let theSubView = subview as! UIView
                        theSubView.removeFromSuperview()
                        self.addSubview(theSubView)
                        theSubView.frame = CGRectMake(self.frame.size.width - theSubView.frame.size.width, 0, theSubView.frame.size.width, theSubView.frame.size.height)
                       
                    }
    
                }
            }
        }
       
        //删除UIView的badge
        func removeBadge() -> Void{
            for subview in self.subviews{
                let strClassName = String(UTF8String: object_getClassName(subview))
                if strClassName == "UITabBarButtonBadge" || strClassName == "_UIBadgeView"{
                    let theSubView = subview as! UIView
                    theSubView.removeFromSuperview()
                }
            }
        }
    }
    
  • 相关阅读:
    grunt 记录
    angularjs 剪贴板
    translate
    鼠标事件
    Typora书写macdown语法教程
    idea常用插件安装
    JDBC使用8.0驱动包连接mysql设置时区serverTimezone
    多服务器部署脚本
    jar包重启脚本-restart.sh
    spring-boot分环境打包为tar包
  • 原文地址:https://www.cnblogs.com/rambot/p/4777484.html
Copyright © 2020-2023  润新知