处理tabbar
处理HomeRankContentVC去除弹性效果 - 适配HWPanModal下拉效果
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user