From a72aae84ef6e8ac448b94bdaeaa7905719bb5300 Mon Sep 17 00:00:00 2001 From: CodeST <694468528@qq.com> Date: Thu, 6 Nov 2025 19:29:52 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=84=E7=90=86tabbar=20=E5=A4=84=E7=90=86Ho?= =?UTF-8?q?meRankContentVC=E5=8E=BB=E9=99=A4=E5=BC=B9=E6=80=A7=E6=95=88?= =?UTF-8?q?=E6=9E=9C=20-=20=E9=80=82=E9=85=8DHWPanModal=E4=B8=8B=E6=8B=89?= =?UTF-8?q?=E6=95=88=E6=9E=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- keyBoard.xcodeproj/project.pbxproj | 6 +- keyBoard/Class/Base/VC/BaseTabBarController.m | 61 +++++++++++++++++-- keyBoard/Class/Home/VC/HomeRankContentVC.m | 1 + 3 files changed, 61 insertions(+), 7 deletions(-) diff --git a/keyBoard.xcodeproj/project.pbxproj b/keyBoard.xcodeproj/project.pbxproj index 2fde4eb..9e0c76e 100644 --- a/keyBoard.xcodeproj/project.pbxproj +++ b/keyBoard.xcodeproj/project.pbxproj @@ -665,8 +665,10 @@ 04FC95BF2EB1E3B1007BD342 /* Class */ = { isa = PBXGroup; children = ( - 047C65492EBCBA880035E841 /* Community */, + 04FC95B62EB1E3B1007BD342 /* Home */, 047C654D2EBCBA880035E841 /* Shop */, + 047C65492EBCBA880035E841 /* Community */, + 04FC95BE2EB1E3B1007BD342 /* Me */, 047C652C2EBCAAAC0035E841 /* Resource */, 04FC95EE2EB3399D007BD342 /* Manager */, 04FC95ED2EB33611007BD342 /* Login */, @@ -675,8 +677,6 @@ 04FC95E12EB20AD1007BD342 /* Guard */, 04FC95C62EB1E4AB007BD342 /* Base */, 04FC95BA2EB1E3B1007BD342 /* Main */, - 04FC95B62EB1E3B1007BD342 /* Home */, - 04FC95BE2EB1E3B1007BD342 /* Me */, ); path = Class; sourceTree = ""; diff --git a/keyBoard/Class/Base/VC/BaseTabBarController.m b/keyBoard/Class/Base/VC/BaseTabBarController.m index 87ba3e7..b24d801 100644 --- a/keyBoard/Class/Base/VC/BaseTabBarController.m +++ b/keyBoard/Class/Base/VC/BaseTabBarController.m @@ -24,18 +24,43 @@ [super viewDidLoad]; [self setupTabbarAppearance]; - // Setup two tabs: Home & My, each embedded in BaseNavigationController + + // 组装 4 个 Tab:首页 / 商城 / 社区 / 我的 + // 图标位于 Assets.xcassets/Tabbar 下:tab_home/tab_home_selected 等 + + // 首页 HomeMainVC *home = [[HomeMainVC alloc] init]; home.title = @"首页"; BaseNavigationController *navHome = [[BaseNavigationController alloc] initWithRootViewController:home]; - navHome.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"首页" image:nil selectedImage:nil]; + navHome.tabBarItem = [self tabItemWithTitle:@"首页" + image:@"tab_home" + selectedImg:@"tab_home_selected"]; + // 商城 + KBShopVC *shop = [[KBShopVC alloc] init]; + shop.title = @"商城"; + BaseNavigationController *navShop = [[BaseNavigationController alloc] initWithRootViewController:shop]; + navShop.tabBarItem = [self tabItemWithTitle:@"商城" + image:@"tab_shop" + selectedImg:@"tab_shop_selected"]; + + // 社区 + KBCommunityVC *community = [[KBCommunityVC alloc] init]; + community.title = @"社区"; + BaseNavigationController *navCommunity = [[BaseNavigationController alloc] initWithRootViewController:community]; + navCommunity.tabBarItem = [self tabItemWithTitle:@"社区" + image:@"tab_shequ" + selectedImg:@"tab_shequ_selected"]; + + // 我的 MyVC *my = [[MyVC alloc] init]; my.title = @"我的"; BaseNavigationController *navMy = [[BaseNavigationController alloc] initWithRootViewController:my]; - navMy.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"我的" image:nil selectedImage:nil]; + navMy.tabBarItem = [self tabItemWithTitle:@"我的" + image:@"tab_my" + selectedImg:@"tab_my_selected"]; - self.viewControllers = @[navHome, navMy]; + self.viewControllers = @[navHome, navShop, navCommunity, navMy]; // 测试储存Token /*[[KBAuthManager shared] saveAccessToken:@"TEST" refreshToken:nil expiryDate:[NSDate dateWithTimeIntervalSinceNow:3600] userIdentifier:nil]*/; @@ -48,11 +73,39 @@ 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; 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]; } } +// 统一构造 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; +} + /* #pragma mark - Navigation diff --git a/keyBoard/Class/Home/VC/HomeRankContentVC.m b/keyBoard/Class/Home/VC/HomeRankContentVC.m index 6fcf1d8..50094d8 100644 --- a/keyBoard/Class/Home/VC/HomeRankContentVC.m +++ b/keyBoard/Class/Home/VC/HomeRankContentVC.m @@ -76,6 +76,7 @@ _tableView = [[BaseTableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain]; _tableView.dataSource = self; _tableView.delegate = self; + _tableView.bounces = false; _tableView.separatorStyle = UITableViewCellSeparatorStyleNone; // 设计为卡片式,去掉系统分割线 _tableView.showsVerticalScrollIndicator = NO; _tableView.contentInset = UIEdgeInsetsMake(8, 0, KB_SafeAreaBottom(), 0);