166 lines
5.2 KiB
Objective-C
166 lines
5.2 KiB
Objective-C
//
|
|
// XJBaseTabBarController.m
|
|
// healthQuestion
|
|
//
|
|
// Created by xulei on 2022/8/12.
|
|
//
|
|
|
|
#import "XJBaseTabBarController.h"
|
|
#import "HQTabBar.h"
|
|
#import "XJMyCenterViewController.h"
|
|
#import "ChatListViewController.h"
|
|
//主控制器
|
|
#import "QuestionViewController.h"
|
|
#import "XJSosCenterViewController.h"
|
|
#import "MonitoringWarchViewController.h"
|
|
|
|
//新版首页
|
|
#import "XJHomePageV2ViewController.h"
|
|
|
|
|
|
@interface XJBaseTabBarController ()<UITabBarControllerDelegate>
|
|
|
|
@property (nonatomic,strong) NSMutableArray * VCS;//tabbar root VC
|
|
|
|
@property (nonatomic, assign) BOOL isConnecting;
|
|
|
|
@property (nonatomic, strong) UIActivityIndicatorView *indicatorView;
|
|
|
|
@property (nonatomic, copy) NSDictionary * dictionary;
|
|
|
|
@property (nonatomic, assign) BOOL isPushed;
|
|
|
|
|
|
|
|
|
|
@end
|
|
|
|
@implementation XJBaseTabBarController
|
|
|
|
|
|
- (void)viewDidLoad {
|
|
[super viewDidLoad];
|
|
self.delegate = self;
|
|
//初始化tabbar
|
|
[self setUpTabBar];
|
|
//添加子控制器
|
|
[self setUpAllChildViewController];
|
|
|
|
}
|
|
|
|
- (void)viewWillAppear:(BOOL)animated {
|
|
[super viewWillAppear:animated];
|
|
self.isPushed = NO;
|
|
}
|
|
|
|
- (void)viewWillDisappear:(BOOL)animated {
|
|
self.isPushed = YES;
|
|
}
|
|
|
|
#pragma mark ————— 初始化TabBar —————
|
|
-(void)setUpTabBar{
|
|
//设置背景色 去掉分割线
|
|
[self setValue:[HQTabBar new] forKey:@"tabBar"];
|
|
[self.tabBar setBackgroundColor:[UIColor whiteColor]];
|
|
[self.tabBar setBackgroundImage:[UIImage new]];
|
|
//通过这两个参数来调整badge位置
|
|
// [self.tabBar setTabIconWidth:95];
|
|
// [self.tabBar setBadgeTop:9];
|
|
[[HQTabBar appearance] setTranslucent:NO];
|
|
}
|
|
|
|
#pragma mark -——————— 初始化VC ————————
|
|
-(void)setUpAllChildViewController{
|
|
_VCS = @[].mutableCopy;
|
|
|
|
//新增首页
|
|
|
|
XJHomePageV2ViewController * homeVC = [[XJHomePageV2ViewController alloc]init];
|
|
[self setupChildViewController:homeVC title:@"首页" imageName:@"xjHomeTabBar_nomal" seleceImageName:@"xjHomeTabBar_selected"];
|
|
|
|
QuestionViewController * questionVC = [[QuestionViewController alloc]init];
|
|
[self setupChildViewController:questionVC title:@"咨询" imageName:@"questionTabBar_nomal" seleceImageName:@"questionTabBar_selected"];
|
|
|
|
|
|
XJSosCenterViewController * sosVC = [[XJSosCenterViewController alloc]init];
|
|
[self setupChildViewController:sosVC title:@"应急" imageName:@"sosCenterTabBar_nomal" seleceImageName:@"sosCenterTabBar_selected"];
|
|
|
|
MonitoringWarchViewController * jianceVC = [[MonitoringWarchViewController alloc]init];
|
|
[self setupChildViewController:jianceVC title:@"监测" imageName:@"monitoringTabBar_nomal" seleceImageName:@"monitoringTabBar_selected"];
|
|
|
|
|
|
XJMyCenterViewController * centerVC = [[XJMyCenterViewController alloc] init];
|
|
[self setupChildViewController:centerVC title:@"我的" imageName:@"mineTabBar_nomal" seleceImageName:@"mineTabBar_selected"];
|
|
|
|
|
|
self.viewControllers = _VCS;
|
|
|
|
}
|
|
|
|
|
|
-(void)setupChildViewController:(UIViewController*)controller title:(NSString *)title imageName:(NSString *)imageName seleceImageName:(NSString *)selectImageName{
|
|
controller.title = title;
|
|
controller.tabBarItem.title = title;//跟上面一样效果
|
|
controller.tabBarItem.image = [[UIImage imageNamed:imageName] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
|
|
controller.tabBarItem.selectedImage = [[UIImage imageNamed:selectImageName] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
|
|
//未选中字体颜色
|
|
[controller.tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName:UIColorHex(#666666),NSFontAttributeName:SYSTEMFONT(10.0f)} forState:UIControlStateNormal];
|
|
//选中字体颜色
|
|
|
|
[controller.tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName:UIColorHex(#21BEBD),NSFontAttributeName:SYSTEMFONT(10.0f)} forState:UIControlStateSelected];
|
|
//包装导航控制器
|
|
XJBaseNavigationController *nav = [[XJBaseNavigationController alloc]initWithRootViewController:controller];
|
|
|
|
[_VCS addObject:nav];
|
|
|
|
}
|
|
-(void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
|
|
{
|
|
// tabbarSelect = [NSString stringWithFormat:@"%ld",tabBarController.selectedIndex];
|
|
}
|
|
|
|
|
|
- (void)didReceiveMemoryWarning {
|
|
[super didReceiveMemoryWarning];
|
|
// Dispose of any resources that can be recreated.
|
|
}
|
|
|
|
|
|
- (void)dealloc {
|
|
|
|
}
|
|
|
|
#pragma mark - auto rotate
|
|
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
|
|
|
|
return [self.selectedViewController preferredInterfaceOrientationForPresentation];
|
|
}
|
|
|
|
- (BOOL)shouldAutorotate {
|
|
|
|
return [self.selectedViewController shouldAutorotate];
|
|
}
|
|
|
|
- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
|
|
|
|
return [self.selectedViewController supportedInterfaceOrientations];
|
|
}
|
|
|
|
- (void)selectedQuestion {
|
|
|
|
self.selectedIndex = 1;
|
|
}
|
|
|
|
/*
|
|
#pragma mark - Navigation
|
|
|
|
// In a storyboard-based application, you will often want to do a little preparation before navigation
|
|
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
|
|
// Get the new view controller using [segue destinationViewController].
|
|
// Pass the selected object to the new view controller.
|
|
}
|
|
*/
|
|
|
|
@end
|
|
|