I have previously written an article to show badge on any uiview, but the ios6 fails. It turns out that Apple has changed the badge class name, so it is compatible here. The source code is as follows:
-(Uiview *) showbadgevalue :( nsstring *) strbadgevalue {uitabbar * tabbar = [[uitabbar alloc] initwithframe: cgrectmake (0, 0,320, 50)]; uitabbaritem * Item = [[uitabbaritem alloc] initwithtitle: @ "Image: Nil Tag: 0]; item. badgevalue = strbadgevalue; nsarray * array = [[nsarray alloc] initwithobjects: item, nil]; tabbar. items = array; [item release]; [array release]; // search for (uiview * viewtab in tabbar. subviews) {for (uiview * subview in viewtab. subviews) {nsstring * strclassname = [nsstring stringwithuf8string: object_getclassname (subview)]; If ([strclassname isw.tostring: @ "uitabbarbuttonbadge"] | [strclassname isw.tostring: @ "_ uibadgeview"]) {// remove [subview removefromsuperview] from the original view; // [self addsubview: subview]; subview. frame = cgrectmake (self. frame. size. width-subview.frame.size.width, 0, subview. frame. size. width, subview. frame. size. height); [tabbar release]; return subview ;}} [tabbar release]; return nil ;}- (void) removebadgevalue {// For (uiview * subview in self. subviews) {nsstring * strclassname = [nsstring stringwithuf8string: object_getclassname (subview)]; If ([strclassname isw.tostring: @ "uitabbarbuttonbadge"] | [strclassname isw.tostring: @ "_ uibadgeview"]) {[subview removefromsuperview]; break ;}}}
One method is used to show badge, and the other is used to hide (remove.