iOS如何自定义的设置UITabbarItem的badge
2016-10-19 14:33
686 查看
本文的代码实现效果如下:
除了第三个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;
}
}
}
除了第三个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;
}
}
}
相关文章推荐
- ios 开发中,如何设置 uitabbar 里面 tabbaritem 不显示文字,只显示图片,图片垂直居中?
- ios UITabBar UITabBarItem 设置角标 数字 红点 未读消息数量
- iOS UITabBarItem 选中图的颜色,设置UIimage的渲染模式
- iOS开中设置UITabBar的背景图片以及各个item的选中图片和未选中
- iOS开发--一些UITabBarItem属性的设置
- IOS 如何给自定义按钮设置选中的效果
- ios之UITabBarItem显示真实自定义的图片而非颜色填充
- iOS开发- UITabBarItem自定义图片(去除灰色)
- iOS: 如何调节UITabbarItem的图片和文字位置
- iOS UITabBarController底部tabbar的item间距设置
- iOS 将navigationItem.titleView设置为自定义UISearchBar (Ficow实例讲解)
- iOS开发- UITabBarItem自定义图片
- iOS 自定义UITabbarController中的item (swift)
- Swift中如何通过KVC将自定义的UITabbar设置为UITabbarController的tabbar
- iOS 开发 中级:UIToolbar,UINavigationBar,UITabBar,UIBarButtonItem,UITabBarItem自定义方法总结 [转]
- iOS 开发 中级:UIToolbar,UINavigationBar,UITabBar,UIBarButtonItem,UITabBarItem自定义方法总结
- ios之UITabBarItem显示真实自定义的图片而非颜色填充
- iOS开发--一些UITabBarItem属性的设置[转]
- iOS开发- UITabBarController的TabBar、TabBarItem背景颜色设置
- iOS tabbaritem设置红点大小、自定义宽高