Files
xj-ios/XinjiangProject/XinjiangProject/Project/Base/HQBaseTabBarController.m
T

157 lines
4.8 KiB
Objective-C

//
// HQBaseTabBarController.m
// healthQuestion
//
// Created by xulei on 2022/8/12.
//
#import "HQBaseTabBarController.h"
#import "HQTabBar.h"
#import "XJMyCenterViewController.h"
#import "ChatListViewController.h"
//主控制器
#import "QuestionViewController.h"
#import "XJSosCenterViewController.h"
#import "MonitoringWarchViewController.h"
//干预二期
@interface HQBaseTabBarController ()<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 HQBaseTabBarController
- (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;
QuestionViewController * questionVC = [[QuestionViewController alloc]init];
[self setupChildViewController:questionVC title:@"咨询" imageName:@"Question_normal_icon" seleceImageName:@"Question_selected_icon"];
XJSosCenterViewController * sosVC = [[XJSosCenterViewController alloc]init];
[self setupChildViewController:sosVC title:@"就医" imageName:@"Question_normal_icon" seleceImageName:@"Question_selected_icon"];
MonitoringWarchViewController * jianceVC = [[MonitoringWarchViewController alloc]init];
[self setupChildViewController:jianceVC title:@"监测" imageName:@"Question_normal_icon" seleceImageName:@"Question_selected_icon"];
XJMyCenterViewController * centerVC = [[XJMyCenterViewController alloc] init];
[self setupChildViewController:centerVC title:@"我的" imageName:@"mine_normal" seleceImageName:@"mine_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];
//包装导航控制器
HQBaseNavigationController *nav = [[HQBaseNavigationController 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];
}
/*
#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