Extension uiview{//any UIView Add badge func showbadgevalue (#strBadgeValue: String), void{let TabB AR = Uitabbar (frame:cgrectmake (0, 0, +)) Let item = Uitabbaritem (title: "", Image:nil, tag:0) item. Badgevalue = strbadgevalue Let array = [item] tabbar.items = array for viewtab in Tabbar.subvi ews{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)}}}}//delete UIView badge fun C Removebadge (), void{for Subview in self.subviews{let strClassName = String (utf8string:object_ge Tclassname (Subview)) if strClassName = = "Uitabbarbuttonbadge" | | strClassName = = "_uibadgeview" {Let Thesubview = Subview as! UIView Thesubview.removefromsuperview ()}}}}
Add badge to UIView in Swift