iOS如何自定义的设置UITabbarItem的badge

来源:互联网 发布:php实现硬件设备对接 编辑:程序博客网 时间:2024/05/29 11:56

本文的代码实现效果如下:


除了第三个tabbarItem显示数字,其他的都显示红点



代码如下:

//tabbar消息未读数量- (void)showUnreadCountViewItemNO:(NSInteger)index unReadCountSum:(NSInteger)unReadCountSum {    UILabel *bageView = (UILabel*)[self.tabBarController.tabBar subviewWithTag:1000+index];    if(unReadCountSum){        if(!bageView){            bageView = [[UILabel alloc] init];            bageView.backgroundColor = kDefaultColor;            bageView.tag = 1000+index;            [self.tabBarController.tabBar addSubview:bageView];            if(index == 2){                bageView.frame=CGRectMake(WIDTH/4/2+WIDTH/4*index+8, 4, 16, 16);                [CALayer updateControlLayer:bageView.layer radius:8 borderWidth:0 borderColor:nil];                bageView.textAlignment = NSTextAlignmentCenter;                bageView.textColor = WHITE_COLOR;            }else{                bageView.frame=CGRectMake(WIDTH/4/2+WIDTH/4*index+8, 4, 10, 10);                [CALayer updateControlLayer:bageView.layer radius:5 borderWidth:0 borderColor:nil];            }        }        if(index == 2){            NSString *numStr;            if(unReadCountSum>100){                numStr = @"99+";                bageView.font = FONT_SYSTEM_SIZE(10);            }else{                numStr = [NSString stringWithFormat:@"%ld", (long)unReadCountSum];                bageView.font = FONT_SYSTEM_SIZE(12);            }            bageView.text = numStr;            [UIApplication sharedApplication].applicationIconBadgeNumber = unReadCountSum;        }    }else{        if(bageView){            [bageView removeFromSuperview];        }        if(index==2){            [UIApplication sharedApplication].applicationIconBadgeNumber = unReadCountSum;        }    }}


0 0
原创粉丝点击