NewBasicTabbarController.m 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. //
  2. // NewBasicTabbarController.m
  3. // MingMen
  4. //
  5. // Created by 罗云飞 on 2017/3/9.
  6. // Copyright © 2017年 罗云飞. All rights reserved.
  7. //
  8. #import "NewBasicTabbarController.h"
  9. #import "HomeRootVC.h"//首页
  10. #import "TechnologyVC.h"//技术
  11. #import "ConversationVC.h"//交谈
  12. #import "MineVC.h"//我的
  13. #import "AmoytechniqueViewController.h"//淘技
  14. #import "FXViewController.h"//发现
  15. #import "ZCJDViewController.h"
  16. #import "NewMineViewController.h"
  17. #import "GUWENViewController.h"//顾问
  18. #import "JitaoHomeViewController.h"//技淘首页
  19. #import "NewFXViewController.h"
  20. #import "NewMyViewController.h"
  21. @interface NewBasicTabbarController ()<UITabBarControllerDelegate>
  22. @end
  23. static NewBasicTabbarController *sharedObj = nil;
  24. static dispatch_once_t onceToken;
  25. @implementation NewBasicTabbarController
  26. + (NewBasicTabbarController *) sharedInstance
  27. {
  28. //static dispatch_once_t onceToken = 0;
  29. dispatch_once(&onceToken, ^{
  30. sharedObj = [[super allocWithZone: NULL] init];
  31. });
  32. return sharedObj;
  33. }
  34. + (id) allocWithZone:(struct _NSZone *)zone
  35. {
  36. return [self sharedInstance];
  37. }
  38. - (id) copyWithZone:(NSZone *) zone
  39. {
  40. return self;
  41. }
  42. +(void)objectDealloc{
  43. // 只有置成0,GCD才会认为它从未执行过.它默认为0.这样才能保证下次再次调用shareInstance的时候,再次创建对象.
  44. // 应用场景:切换账号、从新登陆
  45. onceToken = 0;
  46. sharedObj = nil;
  47. }
  48. - (void)viewDidLoad {
  49. [super viewDidLoad];
  50. // Do any additional setup after loading the view.
  51. [self loadsView];
  52. self.tabBar.barTintColor = [UIColor whiteColor];
  53. //self.tabBar.translucent = YES;//设置不透明背景
  54. /*
  55. //更改tabBar顶部线条颜色
  56. CGRect rect = CGRectMake(0, 0, SCREEN_WIDTH, 1);
  57. UIGraphicsBeginImageContext(rect.size);
  58. CGContextRef context = UIGraphicsGetCurrentContext();
  59. CGContextSetFillColorWithColor(context,
  60. NewNavigationColor.CGColor);
  61. CGContextFillRect(context, rect);
  62. UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
  63. UIGraphicsEndImageContext();
  64. [self.tabBar setShadowImage:img];
  65. [self.tabBar setBackgroundImage:[[UIImage alloc]init]];
  66. */
  67. }
  68. // 初始化所有子控制器
  69. - (void)loadsView{
  70. [self setTabBarChildController:[[JitaoHomeViewController alloc] init] title:@"技淘" image:@"jt-min" selectImage:@"jtxz-min"];
  71. [self setTabBarChildController:[[GUWENViewController alloc] init] title:@"顾问" image:@"gw-min" selectImage:@"gwxz-min"];
  72. [self setTabBarChildController:[[NewFXViewController alloc] init] title:@"发现" image:@"fx-min" selectImage:@"fxxz-min"];
  73. [self setTabBarChildController:[[NewMyViewController alloc] init] title:@"我的" image:@"wd-min" selectImage:@"wdxz-min"];
  74. }
  75. // 添加tabbar的子viewcontroller
  76. - (void)setTabBarChildController:(UIViewController*)controller title:(NSString*)title image:(NSString*)imageStr selectImage:(NSString*)selectImageStr{
  77. UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:controller];
  78. nav.tabBarItem.title = title;
  79. // if ([title isEqualToString:@"FM"]) {
  80. // nav.tabBarItem.titlePositionAdjustment = UIOffsetMake(0, -10);
  81. // }
  82. nav.tabBarItem.image = [[UIImage imageNamed:imageStr]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
  83. nav.tabBarItem.selectedImage = [[UIImage imageNamed:selectImageStr]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
  84. [nav.tabBarItem setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:12],NSForegroundColorAttributeName:[UIColor colorWithString:@"#3C3C3C"]} forState:UIControlStateNormal];//NewRGBColor(74, 74, 74, 1.0)
  85. [nav.tabBarItem setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:12],NSForegroundColorAttributeName:NewButtonColor} forState:UIControlStateSelected];//NewRGBColor(255, 150, 38, 1.0)
  86. [self addChildViewController:nav];
  87. }
  88. - (void)changeRootViewControllerEvent:(NSInteger)changeIndex{
  89. [self setSelectedIndex:changeIndex];
  90. //__weak typeof(self) wself = self;
  91. //[wself setSelectedIndex:changeIndex];
  92. }
  93. - (void)dealloc
  94. {
  95. NSLog(@"Tabbar单例类销毁");
  96. }
  97. - (void)didReceiveMemoryWarning {
  98. [super didReceiveMemoryWarning];
  99. // Dispose of any resources that can be recreated.
  100. }
  101. /*
  102. #pragma mark - Navigation
  103. // In a storyboard-based application, you will often want to do a little preparation before navigation
  104. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  105. // Get the new view controller using [segue destinationViewController].
  106. // Pass the selected object to the new view controller.
  107. }
  108. */
  109. @end