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"
|
2025-10-31 16:50:15 +08:00
|
|
|
|
#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];
|
2025-11-06 19:29:52 +08:00
|
|
|
|
|
|
|
|
|
|
// 组装 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")
|
2025-11-06 19:29:52 +08:00
|
|
|
|
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")
|
2025-11-06 19:29:52 +08:00
|
|
|
|
image:@"tab_shop"
|
|
|
|
|
|
selectedImg:@"tab_shop_selected"];
|
2025-10-29 14:28:57 +08:00
|
|
|
|
|
2025-11-06 19:29:52 +08:00
|
|
|
|
// 社区
|
|
|
|
|
|
KBCommunityVC *community = [[KBCommunityVC alloc] init];
|
2025-11-17 20:55:11 +08:00
|
|
|
|
// community.title = KBLocalized(@"Circle");
|
2025-11-06 19:29:52 +08:00
|
|
|
|
BaseNavigationController *navCommunity = [[BaseNavigationController alloc] initWithRootViewController:community];
|
2025-11-17 20:07:39 +08:00
|
|
|
|
navCommunity.tabBarItem = [self tabItemWithTitle:KBLocalized(@"Circle")
|
2025-11-06 19:29:52 +08:00
|
|
|
|
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")
|
2025-11-06 19:29:52 +08:00
|
|
|
|
image:@"tab_my"
|
|
|
|
|
|
selectedImg:@"tab_my_selected"];
|
2025-10-29 14:28:57 +08:00
|
|
|
|
|
2025-11-06 19:29:52 +08:00
|
|
|
|
self.viewControllers = @[navHome, navShop, navCommunity, navMy];
|
2025-10-31 16:50:15 +08:00
|
|
|
|
|
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];
|
2025-11-06 19:29:52 +08:00
|
|
|
|
// 设置选中标题为黑色(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;
|
2025-11-06 19:29:52 +08:00
|
|
|
|
} 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
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-11-06 19:29:52 +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
|