AS_TabBarViewController.m 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. //
  2. // AS_TabBarViewController.m
  3. // Asteria
  4. //
  5. // Created by 王猛 on 2023/5/6.
  6. //
  7. //
  8. #import "AS_TabBarViewController.h"
  9. #import <UCMBaseC.h>
  10. #import "AViewController.h"
  11. @class APCategoryViewController;
  12. @interface AS_TabBarViewController ()<UITabBarControllerDelegate>
  13. @end
  14. @implementation AS_TabBarViewController
  15. - (void)didInitialize {
  16. [super didInitialize];
  17. self.tabBar.backgroundColor = UIColor.whiteColor;
  18. self.tabBar.unselectedItemTintColor = Col_666;
  19. self.tabBar.tintColor = _1CBC9D;
  20. UIViewController *vc1 = [[CTMediator sharedInstance] getCategoryListVc:@{}];
  21. UIViewController *vc2 = [[CTMediator sharedInstance] getHomeVc:@{}];
  22. AViewController *cartv = [AViewController new];
  23. UIViewController *vc3 = [[CTMediator sharedInstance] getUserCenterVc:@{}];
  24. NSArray *vcAry = @[vc2, vc1, cartv, vc3];
  25. NSArray *titleArr = @[@"SHOP",@"CATEGORY",@"CART", @"ME"];
  26. NSArray *imgArr = @[@"tab_home", @"tab_category", @"tab_cart",@"tab_me"];
  27. NSArray *selimgArr = @[@"tab_home_sel", @"tab_category_sel",@"tab_cart_sel" , @"tab_me_sel"];
  28. NSMutableArray *tabvcAry = [[NSMutableArray alloc]init];
  29. for (int i= 0; i<titleArr.count; i++) {
  30. QMUINavigationController *uikitNavController = [[QMUINavigationController alloc] initWithRootViewController:vcAry[i]];
  31. UITabBarItem *tabBarItem = [[UITabBarItem alloc] initWithTitle:titleArr[i] image:[UIImageMake(imgArr[i]) imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] tag:i];
  32. if (i == 2) {
  33. tabBarItem.qmui_badgeFont = [UIFont fontWithName:Rob_Regular size:11];
  34. tabBarItem.qmui_badgeOffset = CGPointMake(-8, 13);
  35. tabBarItem.qmui_badgeContentEdgeInsets = UIEdgeInsetsMake(3, 3, 3, 3);
  36. tabBarItem.qmui_badgeInteger = 0;
  37. tabBarItem.qmui_badgeTextColor = Col_FFF;
  38. tabBarItem.qmui_badgeBackgroundColor = Col_000;
  39. }
  40. tabBarItem.selectedImage = [UIImageMake(selimgArr[i]) imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
  41. uikitNavController.tabBarItem = tabBarItem;
  42. [tabvcAry addObject:uikitNavController];
  43. }
  44. self.viewControllers = tabvcAry;
  45. self.delegate = self;
  46. }
  47. - (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item {
  48. if (self.tabBar.items.count > 2) {
  49. UITabBarItem *temp = self.tabBar.items[2];
  50. temp.qmui_badgeInteger = arc4random()%100;
  51. }
  52. }
  53. - (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController {
  54. if ([viewController isKindOfClass:QMUINavigationController.class]) {
  55. QMUINavigationController *nav = (QMUINavigationController *)viewController;
  56. UIViewController *vc = nav.qmui_rootViewController;
  57. if ([vc isKindOfClass:[CTMediator.sharedInstance categoryListVcClass]]) {
  58. UIViewController *vc1 = [[CTMediator sharedInstance] getCategoryListVc:@{}];
  59. [self.selectedViewController pushViewController:vc1 animated:true];
  60. return false;
  61. }
  62. if ([vc isKindOfClass:[CTMediator.sharedInstance userCenterVcClass]]) {
  63. if (![ASUserInfoManager.shared isLogin]) {
  64. UIViewController *loginC = [[CTMediator sharedInstance] Login_LoginC:@{}];
  65. QMUINavigationController *uikitNavController = [[QMUINavigationController alloc] initWithRootViewController:loginC];
  66. uikitNavController.navigationBar.hidden = YES;
  67. uikitNavController.modalPresentationStyle =UIModalPresentationFullScreen;
  68. [self.selectedViewController presentViewController:uikitNavController animated:YES completion:nil];
  69. return false;
  70. } else {
  71. [ASUserInfoManager.shared getInfo];
  72. }
  73. }
  74. }
  75. return true;
  76. }
  77. @end