Files
keyboard/keyBoard/Class/Base/VC/BaseTabBarController.m

118 lines
5.0 KiB
Mathematica
Raw Normal View History

2025-10-29 14:17:26 +08:00
//
// BaseTabBarController.m
// keyBoard
//
// Created by Mac on 2025/10/29.
//
#import "BaseTabBarController.h"
#import "HomeVC.h"
2025-11-06 16:05:28 +08:00
#import "HomeMainVC.h"
2025-10-29 14:17:26 +08:00
#import "MyVC.h"
2025-11-06 19:19:12 +08:00
#import "KBShopVC.h"
#import "KBCommunityVC.h"
2025-10-29 14:28:57 +08:00
#import "BaseNavigationController.h"
#import "KBAuthManager.h"
2025-10-29 14:17:26 +08:00
@interface BaseTabBarController ()
@end
@implementation BaseTabBarController
- (void)viewDidLoad {
[super viewDidLoad];
2025-11-06 16:57:28 +08:00
[self setupTabbarAppearance];
// 4 Tab / / /
// Assets.xcassets/Tabbar tab_home/tab_home_selected
//
2025-11-06 16:05:28 +08:00
HomeMainVC *home = [[HomeMainVC alloc] init];
2025-10-29 14:28:57 +08:00
BaseNavigationController *navHome = [[BaseNavigationController alloc] initWithRootViewController:home];
2025-11-17 20:07:39 +08:00
navHome.tabBarItem = [self tabItemWithTitle:KBLocalized(@"Home")
image:@"tab_home"
selectedImg:@"tab_home_selected"];
//
KBShopVC *shop = [[KBShopVC alloc] init];
BaseNavigationController *navShop = [[BaseNavigationController alloc] initWithRootViewController:shop];
2025-11-17 20:07:39 +08:00
navShop.tabBarItem = [self tabItemWithTitle:KBLocalized(@"Shop")
image:@"tab_shop"
selectedImg:@"tab_shop_selected"];
2025-10-29 14:28:57 +08:00
//
KBCommunityVC *community = [[KBCommunityVC alloc] init];
2025-11-17 20:07:39 +08:00
community.title = KBLocalized(@"社区");
BaseNavigationController *navCommunity = [[BaseNavigationController alloc] initWithRootViewController:community];
2025-11-17 20:07:39 +08:00
navCommunity.tabBarItem = [self tabItemWithTitle:KBLocalized(@"Circle")
image:@"tab_shequ"
selectedImg:@"tab_shequ_selected"];
//
2025-10-29 14:28:57 +08:00
MyVC *my = [[MyVC alloc] init];
BaseNavigationController *navMy = [[BaseNavigationController alloc] initWithRootViewController:my];
2025-11-17 20:07:39 +08:00
navMy.tabBarItem = [self tabItemWithTitle:KBLocalized(@"Mine")
image:@"tab_my"
selectedImg:@"tab_my_selected"];
2025-10-29 14:28:57 +08:00
self.viewControllers = @[navHome, navShop, navCommunity, navMy];
2025-11-06 16:05:28 +08:00
// Token
2025-11-12 19:46:07 +08:00
// [[KBAuthManager shared] saveAccessToken:@"TEST" refreshToken:nil expiryDate:[NSDate dateWithTimeIntervalSinceNow:3600] userIdentifier:nil];
[[KBAuthManager shared] signOut];
2025-10-29 14:17:26 +08:00
}
2025-11-06 16:57:28 +08:00
- (void)setupTabbarAppearance{
// TabBar view TabBar
self.tabBar.translucent = NO;
if (@available(iOS 15.0, *)) {
UITabBarAppearance *a = [UITabBarAppearance new];
[a configureWithOpaqueBackground];
a.backgroundColor = [UIColor whiteColor];
// iOS 15+ appearance
NSDictionary *selAttr = @{ NSForegroundColorAttributeName : [UIColor blackColor] };
a.stackedLayoutAppearance.selected.titleTextAttributes = selAttr;
a.inlineLayoutAppearance.selected.titleTextAttributes = selAttr;
a.compactInlineLayoutAppearance.selected.titleTextAttributes = selAttr;
2025-11-06 16:57:28 +08:00
self.tabBar.standardAppearance = a;
self.tabBar.scrollEdgeAppearance = a;
} else if (@available(iOS 13.0, *)) {
UITabBarAppearance *a = [UITabBarAppearance new];
[a configureWithOpaqueBackground];
a.backgroundColor = [UIColor whiteColor];
NSDictionary *selAttr = @{ NSForegroundColorAttributeName : [UIColor blackColor] };
a.stackedLayoutAppearance.selected.titleTextAttributes = selAttr;
a.inlineLayoutAppearance.selected.titleTextAttributes = selAttr;
a.compactInlineLayoutAppearance.selected.titleTextAttributes = selAttr;
self.tabBar.standardAppearance = a;
self.tabBar.tintColor = [UIColor blackColor];
} else {
// tintColor/appearance 退
self.tabBar.tintColor = [UIColor blackColor];
[[UITabBarItem appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor blackColor]}
forState:UIControlStateSelected];
2025-11-06 16:57:28 +08:00
}
}
// TabBarItem Tint
- (UITabBarItem *)tabItemWithTitle:(NSString *)title image:(NSString *)imageName selectedImg:(NSString *)selectedName {
UIImage *img = [[UIImage imageNamed:imageName] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
UIImage *sel = [[UIImage imageNamed:selectedName] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
UITabBarItem *item = [[UITabBarItem alloc] initWithTitle:title image:img selectedImage:sel];
return item;
}
2025-10-29 14:17:26 +08:00
/*
#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