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:
[Plain]
-(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 from the original view
[Subview removeFromSuperview];
//
[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;
}
}
}