| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145 |
- //
- // CTTabbarController.m
- // wct_tabbar
- //
- // Created by Wcting on 2019/4/24.
- // Copyright © 2019年 EJIAJX_wct. All rights reserved.
- //
- #import "CTTabbarController.h"
- #import "ViewController.h"
- #import "UINavigationController+FDFullscreenPopGesture.h"
- @interface CTTabbarController ()
- @property (nonatomic, strong)NSArray *arrTabImage;
- @property (nonatomic, strong)UIButton *buttonCurrent; //保存当前选中的按钮
- @property (nonatomic, assign)NSInteger selectIndex;
- @end
- static CTTabbarController *tabbarController = nil;
- @implementation CTTabbarController
- +(CTTabbarController *)sharaTabbarController
- {
- static dispatch_once_t onceToken;
- dispatch_once(&onceToken, ^{
- tabbarController = [[CTTabbarController alloc] init];
- });
- return tabbarController;
- }
- - (void)viewDidLoad {
- [super viewDidLoad];
- // Do any additional setup after loading the view.
- // self.view.backgroundColor = [UIColor redColor];
- [self currentController];
-
- }
- - (void)currentController
- {
- //首页 - 使用新版首页
- self.vc1 = [[NewHomeViewController alloc] init];
-
- //短剧
- self.vc2 = [[JXShortDramaViewController alloc] init];
-
- // 暂时注释掉影视(搜索)页签
- // self.vc3 = [[SearchViewController alloc] init];
-
- //我的
- self.vc4 = [[MineViewController alloc] init];
-
- GDNavigationController *nav1 = [[GDNavigationController alloc] initWithRootViewController:self.vc1];
- GDNavigationController *nav2 = [[GDNavigationController alloc] initWithRootViewController:self.vc2];
- // UINavigationController *nav3 = [[UINavigationController alloc] initWithRootViewController:self.vc3]; // 暂时注释
- GDNavigationController *nav4 = [[GDNavigationController alloc] initWithRootViewController:self.vc4];
- [nav1 setNavigationBarHidden:YES animated:NO];
- [nav2 setNavigationBarHidden:YES animated:NO];
- // [nav3 setNavigationBarHidden:YES animated:NO]; // 暂时注释
- [nav4 setNavigationBarHidden:YES animated:NO];
- NSArray *arrayVC = @[nav1, nav2, nav4]; // 首页、短剧、我的
- [self setViewControllers:arrayVC];
- for(int i=0;i<self.arrTabImage.count;i++){
- if(arrayVC[i]){
- UIViewController *controller = arrayVC[i];
- controller.title=self.arrTabImage[i][@"t"];
- UITabBarItem *item=[[UITabBarItem alloc] initWithTitle:self.arrTabImage[i][@"t"] image:[[UIImage imageNamed:self.arrTabImage[i][@"n"]] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] selectedImage:[[UIImage imageNamed:self.arrTabImage[i][@"s"]] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
- item.tag=100+i;
- controller.tabBarItem=item;
- }
- }
- }
- +(void)initialize {
- UIColor *xcolor = rgba(28, 35, 61, 0.9);
- NSDictionary *attrNormal = @{NSFontAttributeName:[UIFont boldSystemFontOfSize:12],NSForegroundColorAttributeName:rgba(255, 255, 255, 0.6)};
- NSDictionary *attrSelect = [NSDictionary dictionary];
- UITabBar *tabBar = [UITabBar appearance];
- //ios 13 之后需要这样设置才有效
- if (@available(iOS 13.0, *)) {
- attrSelect = @{NSFontAttributeName:[UIFont boldSystemFontOfSize:12],NSForegroundColorAttributeName:UIColorWithRGB(0xFFD400)};
- UITabBarAppearance *tabBarAppearance = [[UITabBarAppearance alloc]init];
- //设置tabar背景色
- tabBarAppearance.backgroundColor = xcolor;
- tabBarAppearance.stackedLayoutAppearance.normal.titleTextAttributes = attrNormal;
- tabBarAppearance.stackedLayoutAppearance.selected.titleTextAttributes = attrSelect;
- //必须要加上这两句
- tabBar.standardAppearance = tabBarAppearance;
- if (@available(iOS 15.0, *)) {
- tabBar.scrollEdgeAppearance = tabBarAppearance;
- } else {
- // Fallback on earlier versions
- }
- } else {
- attrSelect = @{NSFontAttributeName:[UIFont boldSystemFontOfSize:12],NSForegroundColorAttributeName:UIColorWithRGB(0xFFD400)};
- UITabBarItem *tbItem = [UITabBarItem appearance];
- [tbItem setTitleTextAttributes:attrNormal forState:UIControlStateNormal];
- [tbItem setTitleTextAttributes:attrSelect forState:UIControlStateSelected];
- [tabBar setBarTintColor:xcolor]; //tabBar的背景色
- }
- tabBar.translucent = YES; //translucent: 半透明的
- }
- - (UIImage *)imageWithColor:(UIColor *)color
- {
- CGRect rect = CGRectMake(0.0f, 0.0f, 1.0f, 1.0f);
- UIGraphicsBeginImageContext(rect.size);
- CGContextRef context = UIGraphicsGetCurrentContext();
-
- CGContextSetFillColorWithColor(context, [color CGColor]);
- CGContextFillRect(context, rect);
-
- UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
- UIGraphicsEndImageContext();
-
- return image;
- }
- -(void)dealloc{
- }
- -(void)viewDidAppear:(BOOL)animated{
- [super viewDidAppear:animated];
- }
- -(void)viewWillAppear:(BOOL)animated{
- [super viewWillAppear:animated];
- }
- -(NSArray *)arrTabImage
- {
- if (_arrTabImage == nil) {
- _arrTabImage = [NSArray arrayWithObjects:
- @{@"n":@"icon-2.1",@"s":@"icon-1.1",@"t":@"首页"},
- @{@"n":@"icon-2.2",@"s":@"icon-1.2",@"t":@"短剧"},
- // @{@"n":@"Frame 3",@"s":@"Frame 8",@"t":@"搜索"}, // 暂时注释
- @{@"n":@"icon-2.4",@"s":@"icon-1.4",@"t":@"我的"},
- nil];
- }
- return _arrTabImage;
- }
- @end
|