Objective-C (iOS): バッジ

ApplicationIconBadgeViewController

Objective-C: ApplicationIconBadgeViewController.h

#import <UIKit/UIKit.h>

@interface ApplicationIconBadgeViewController : UIViewController

@end

Objective-C: ApplicationIconBadgeViewController.m

#import "ApplicationIconBadgeViewController.h"

@interface ApplicationIconBadgeViewController ()

@end

@implementation ApplicationIconBadgeViewController

UILabel *label_;

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    
    UISlider *slider = [[UISlider alloc] initWithFrame:CGRectMake(0, 20, 320, 0)];
    slider.maximumValue = 9999;
    slider.minimumValue = 0;
    [slider addTarget:self action:@selector(changeValue:) forControlEvents:UIControlEventValueChanged];
    [self.view addSubview:slider];
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 50, 320, 30)];
    [self.view addSubview:label];
    label_ = label;
}
- (void)changeValue:(UISlider *)slider
{
    label_.text = [NSString stringWithFormat:@"%d", [[NSNumber numberWithFloat:slider.value] intValue]];
    [UIApplication sharedApplication].applicationIconBadgeNumber = [[NSNumber numberWithFloat:slider.value] intValue];
}

@end