Many times we need to add some red badge on the Tabbaritem to prompt the user here to appear new content, can see, the most common is the circle of friends, the general Red Circle Badge contains 2 kinds of situations:
1) contains digital display
2) does not contain digital display
By default, the Tabbaritem already has the Badgevalue property, adding badge only need to set a Badgevalue value for item, in the case of 1) performance is very good, but in the case of 2) if the set Badgevalue is @ "" Then the Red badge will be very big and obviously inappropriate, so we need to make some adjustments as follows:
For (UIView *viewtab in tabbar.subviews) {for (UIView *subview in viewtab.subviews) { NSString *strclassname = [N Sstring Stringwithutf8string:object_getclassname (SubView)]; if ([strClassName isequaltostring:@ "Uitabbarbuttonbadge"] | |//* * * IOS 6 Prior is Uitabbarbuttonbadge [ strClassName isequaltostring:@ "_uibadgeview"]) { //* * * IOS posterior is Uitabbarbuttonbadge cgrect Badgeframe = Subview.frame; Badgeframe.size = Cgsizemake (8, 8); Subview.frame = Badgeframe; SubView.layer.masksToBounds = YES; SubView.layer.cornerRadius = 4; Subview.backgroundcolor = [Uicolor redcolor]; return;}}}
first, you need to set the badge to set the item, and then add the above code, that is, the original Badgeview frame redefined a bit.
Tabbaritem of badge