title: Add Push Notification Badge to UIButton
body: <p>I am wanting to add a badge icon to a UIButton within my app when there is a notification sent and I'm not quite sure how to achieve this.  It would need to match the badge on the springboard icon and both the springboard badge and the badge on the UIButton would need to go away when that UIButton is pressed in the app.</p>
  
  <p>UPDATE:</p>
  
  <p>I got a badge to appear but when I open the app the badge gets reset back to zero when the app gets opened so I end up not seeing the badge on the button.  I know the badge works because I tested it by doing this:</p>
  
  <pre><code>[[UIApplication sharedApplication]setApplicationIconBadgeNumber:1];
  </code></pre>
  
  <p>Here is the code for the badge:</p>
  
  <pre><code>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;
      }
  </code></pre>
  
  <p>How can I have the badge not get reset when opening the app, but instead reset when pressing that button in the app?</p>
  
  <p>I have this working but still have one problem.  If the app isn't running in the background, the badge shows up on the springboard icon and on the UIButton.  When the button is pressed, the new view opens and the badge is reset so when the user goes back to the screen with the UIButton, the badge is no longer there.  The issue I'm having is when the app is running in the background, the badge doesn't show on the button, but shows on the springboard. </p>
  
  <pre><code>- (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];
  }  
  </code></pre>
  
  <p>In viewDidLoad</p>
  
  <pre><code>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;
      }
  </code></pre>