Swift中给UIView添加Badge
2015-09-02 01:30
411 查看
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() } } } }
相关文章推荐
- Don’t Put View Code Into Your View Controller别把View创建的代码放在VC中(swift)
- 在Swift中检查API的可用性
- swift - The command pattern
- Swift1
- 初步swift语言学习笔记2(可选类型?和隐式可选类型!)
- Swift Tutorial(swift 教程) 4:Your First App
- swift开发
- swift 总结3
- 女神画廊App (Swift1.2)
- swift总结2
- 最老程序员创业开发实训5---Swift语言极速入门
- 相亲神器记录Swift1.2
- swift总结1
- swift自学注意点
- swift 中#pragma mark 表示方法
- swift详解之二十--------在xcode中使用git管理源代码,将代码提交到github
- swift 添加按钮
- swift - The Chain Responsibility pattern
- swift详解之十九--------------UITableView的基本操作(下拉刷新,新增删除,分组,检索等)
- IOS--Swift 01