<分区>
我想在发送通知时向我的应用程序中的 UIButton 添加角标(Badge)图标,但我不太确定如何实现此目的。它需要与跳板图标上的角标(Badge)相匹配,并且当在应用中按下该 UIButton 时,跳板角标(Badge)和 UIButton 上的角标(Badge)都需要消失。
更新:
我要显示一个角标(Badge),但是当我打开应用程序时,角标(Badge)会在应用程序打开时重置为零,所以我最终在按钮上看不到角标(Badge)。我知道角标(Badge)有效,因为我通过这样做对其进行了测试:
[[UIApplication sharedApplication]setApplicationIconBadgeNumber:1];
这是角标(Badge)的代码:
NSString *badgeNumber = [NSString stringWithFormat:@"%d", [[UIApplication sharedApplication]applicationIconBadgeNumber]];
JSCustomBadge *actionAlertBadge = [JSCustomBadge customBadgeWithString:badgeNumber];
actionAlertBadge.frame = CGRectMake(188, 6, 30, 30);
[self.view addSubview:actionAlertBadge];
if ([badgeNumber isEqual:@"0"])
{
actionAlertBadge.hidden = YES;
}
如何才能让角标(Badge)在打开应用时不重置,而是在应用中按下该按钮时重置?
我有这个工作,但仍然有一个问题。如果应用程序未在后台运行,则角标(Badge)会显示在跳板图标和 UIButton 上。当按下按钮时,新 View 打开并且角标(Badge)被重置,因此当用户返回到带有 UIButton 的屏幕时,角标(Badge)不再存在。我遇到的问题是当应用程序在后台运行时,角标(Badge)没有显示在按钮上,而是显示在跳板上。
- (IBAction)gotoActionAlerts
{
ActionAlertsViewController *actionAlerts = [[ActionAlertsViewController alloc]initWithStyle:UITableViewStylePlain];
WebViewController *wvc = [[WebViewController alloc]init];
[actionAlerts setWebViewController:wvc];
actionAlerts.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[[UAPush shared] resetBadge];
actionAlertBadge.hidden = YES;
[self.navigationController pushViewController:actionAlerts animated:YES];
}
在viewDidLoad中
badgeNumber = [NSString stringWithFormat:@"%d", [[UIApplication sharedApplication]applicationIconBadgeNumber]];
actionAlertBadge = [JSCustomBadge customBadgeWithString:badgeNumber];
actionAlertBadge.frame = CGRectMake(83, 6, 30, 30);
[self.view addSubview:actionAlertBadge];
if ([badgeNumber isEqualToString:@"0"])
{
actionAlertBadge.hidden = YES;
}