码迷,mamicode.com
首页 > 微信 > 详细

添加微信tabbar中有消息的小红点

时间:2014-09-22 18:31:10      阅读:769      评论:0      收藏:0      [点我收藏+]

标签:ios   微信   红点   

添加微信tabbar中有消息的小红点

by 伍雪颖

bubuko.com,布布扣
- (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;
    }
}


添加微信tabbar中有消息的小红点

标签:ios   微信   红点   

原文地址:http://blog.csdn.net/rainlesvio/article/details/39478763

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!