zoukankan      html  css  js  c++  java
  • 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()
                }
            }
        }
    }
    
  • 相关阅读:
    Java MQTT 客户端之 Paho
    Spring Security + JJWT 实现 JWT 认证和授权
    MinIO
    Spring Boot 实现看门狗功能 (调用 Shell 脚本)
    Canal Admin
    canal
    浅尝 Elastic Stack (五) Logstash + Beats + Kafka
    养鸡场下蛋记
    涛声依旧
    原创:矩阵论学习心得
  • 原文地址:https://www.cnblogs.com/rambot/p/4777484.html
Copyright © 2011-2022 走看看