一.系统消息小红点
使用UITabbar+Badge
在UITabBarController实现以下方法
-(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
[self.viewControllers enumerateObjectsUsingBlock:^(__kindof UIViewController * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
if ([obj isKindOfClass:[GPLxiaoxiViewController class]]) {
GPLxiaoxiViewController *chatListVC = (GPLxiaoxiViewController *)obj;
[chatListVC updateExplorBadgeValueForTabBarItem];
}
if ([obj isKindOfClass:[ExploreViewController class]]) {
ExploreViewController *ExploreVC = (ExploreViewController *)obj;
[ExploreVC updateExplorBadgeValueForTabBarItem];
}
}];
}
在对应viewcontroller中实现对应方法
-(void)updateExplorBadgeValueForTabBarItem
{
__weak typeof(self) __weakSelf = self;
dispatch_async(dispatch_get_main_queue(), ^{
NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
NSDictionary *userDic = [user objectForKey:@"UserInfoDic"];
NSString *selfStr = [userDic objectForKey:@"user_id"];
NSString *keyStr1 = [NSString stringWithFormat:@"usermakeorder%@",selfStr];
NSString *keyStr2 = [NSString stringWithFormat:@"sellergetorder%@",selfStr];
NSString *str1 = [user objectForKey:keyStr1];
NSString *str2 = [user objectForKey:keyStr2];
if ([str1 isEqualToString:@"用户向附近商户下单"])
{
[__weakSelf.tabBarController.tabBar showBadgeOnItemIndex:3 badgeValue:10086];
}else if ([str2 isEqualToString:@"有商户接单"])
{
[__weakSelf.tabBarController.tabBar showBadgeOnItemIndex:3 badgeValue:10086];
}
else {
[__weakSelf.tabBarController.tabBar hideBadgeOnItemIndex:3];
}
});
}
二.设置tabbar图标渲染模式
for (UITabBarItem *item in self.tabBar.items) {
item.selectedImage = [item.selectedImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
item.image = [item.image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
//item.title
}
网友评论