- (void)dealloc { [[NSNotificationCenter defaultCenter] removeObserver:kNotificationShowAlertDot]; } - (void)viewDidLoad { [super viewDidLoad]; [self showAlertDot]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(showAlertDot) name:kNotificationShowAlertDot object:nil]; } - (void)showAlertDot { NSArray *savedPath = [WTFileManager filesAtPath:savedDirectoryPath]; if (savedPath.count > 0) { [self refreshTabbarReddotAtIndex:2]; }else { [self hideTabbarReddots]; } } - (void)loadView{ [super loadView]; for (int i = 0; i< 4; i++) { UIImageView *imageView = nil; UIImage *badgeImg = [UIImage imageNamed:@"icon_alert_dot"]; if (i == 2) { imageView = [[UIImageView alloc] initWithImage:badgeImg]; imageView.frame = CGRectMake(50 + i * 80, 7, 6, 6); } else{ imageView = [[UIImageView alloc] initWithImage:badgeImg]; imageView.frame = CGRectMake(47 + i * 80, 5, 11, 11); } imageView.hidden = YES; [self.tabBar addSubview:imageView]; [self.redImageArray addObject:imageView]; } } - (NSMutableArray *)redImageArray { if (!_redImageArray) { _redImageArray = [[NSMutableArray alloc] initWithCapacity:0]; } return _redImageArray; } - (NSMutableArray *)countArray { if (!_countArray) { _countArray = [[NSMutableArray alloc] initWithCapacity:0]; } return _countArray; } - (void)refreshTabbarReddots { for (int i = 0; i < 4; i ++) { [self refreshTabbarReddotAtIndex:i]; } } - (void)refreshTabbarReddotAtIndex:(int)index{ UIImageView *imageView = [self.redImageArray objectAtIndex:index]; if (index == 2) { imageView.hidden = NO; } else{ imageView.hidden = YES; } } - (void)hideTabbarReddots { for (UIImageView *imageView in self.redImageArray) { imageView.hidden = YES; } }
原文地址:http://blog.csdn.net/rainlesvio/article/details/39478763