-(void)viewDidAppear:(BOOL)animated{
[self showBadgeValue:@"10"];
}
- (void)showBadgeValue:(NSString *)strBadgeValue
{
UITabBar *tabBar = [[UITabBar alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0,100, 100)];
[imageView setImage:[UIImage imageNamed:@"background.png"]];
//[self.view addSubview:imageView];
UITabBarItem *item = [[UITabBarItem alloc] initWithTitle:@"jjj" image:imageView.image tag:0];
item.badgeValue = strBadgeValue;
NSArray *array = [[NSArray alloc] initWithObjects:item, nil];
tabBar.items = array;
[self.view addSubview:tabBar];
[item release];
[array release];
//寻找
// for (UIView *viewTab in tabBar.subviews) {
// for (UIView *subview in viewTab.subviews) {
// NSString *strClassName = [NSString stringWithUTF8String:object_getClassName(subview)];
// if ([strClassName isEqualToString:@"UITabBarButtonBadge"] ||
// [strClassName isEqualToString:@"_UIBadgeView"]) {
// //从原视图上移除
// [subview removeFromSuperview];
// //
// [self.view 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];
}
- (void)removeBadgeValue
{
//
for (UIView *subview in self.view.subviews) {
NSString *strClassName = [NSString stringWithUTF8String:object_getClassName(subview)];
if ([strClassName isEqualToString:@"UITabBarButtonBadge"] ||
[strClassName isEqualToString:@"_UIBadgeView"]) {
[subview removeFromSuperview];
break;
}
}
}
[self showBadgeValue:@"10"];
}
- (void)showBadgeValue:(NSString *)strBadgeValue
{
UITabBar *tabBar = [[UITabBar alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0,100, 100)];
[imageView setImage:[UIImage imageNamed:@"background.png"]];
//[self.view addSubview:imageView];
UITabBarItem *item = [[UITabBarItem alloc] initWithTitle:@"jjj" image:imageView.image tag:0];
item.badgeValue = strBadgeValue;
NSArray *array = [[NSArray alloc] initWithObjects:item, nil];
tabBar.items = array;
[self.view addSubview:tabBar];
[item release];
[array release];
//寻找
// for (UIView *viewTab in tabBar.subviews) {
// for (UIView *subview in viewTab.subviews) {
// NSString *strClassName = [NSString stringWithUTF8String:object_getClassName(subview)];
// if ([strClassName isEqualToString:@"UITabBarButtonBadge"] ||
// [strClassName isEqualToString:@"_UIBadgeView"]) {
// //从原视图上移除
// [subview removeFromSuperview];
// //
// [self.view 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];
}
- (void)removeBadgeValue
{
//
for (UIView *subview in self.view.subviews) {
NSString *strClassName = [NSString stringWithUTF8String:object_getClassName(subview)];
if ([strClassName isEqualToString:@"UITabBarButtonBadge"] ||
[strClassName isEqualToString:@"_UIBadgeView"]) {
[subview removeFromSuperview];
break;
}
}
}