iOS 使用系统自带的UITabbarItem的badge,通过setBadgeValue来设置tabar的角标。


先找到需要设置角标的tabbarItem。然后赋值badgeValue,如果想要隐藏的时候只需要把设置tabarItem.badgeValue=nil; 即可。

        UITabBarController * root = self.tabBarController; // self当前的viewController
        
        UITabBarItem * tabBarItem = [UITabBarItem new];
        
        if (root.tabBar.items.count>4) {
            
            tabBarItem = root.tabBar.items[3];// 拿到需要设置角标的tabarItem
            
        }
        
        NSString *rst = [NSString stringWithFormat:@"100"];
        
        int a = [rst intValue];
        
        if (a == 0) {
            [tabBarItem setBadgeValue:nil];// 隐藏角标
        }else if (a > 99) {
            
            [tabBarItem setBadgeValue:@"99+"];
            
        } else {
            
            [tabBarItem setBadgeValue:rst];
            
        }

  


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM