1.iOS 13.0之前的设置代码(在UITabBarController里面)
[[UITabBarItem appearance] setTitleTextAttributes:@{ NSForegroundColorAttributeName:k_title_color_2B,NSFontAttributeName:TEXT_LIT_B_FONT10} forState:UIControlStateNormal];
[[UITabBarItem appearance] setTitleTextAttributes:@{ NSForegroundColorAttributeName:k_main_tab_text_color,NSFontAttributeName:TEXT_LIT_B_FONT10} forState:UIControlStateSelected];
self.delegate = self;
self.tabBar.alpha = 1.0f;
//解决这个问题是 iOS 12.1 Beta 2 引入的问题,只要 UITabBar 是磨砂的,并且 push viewController 时 hidesBottomBarWhenPushed = YES 则手势返回的时候就会触发,出现这个现象的直接原因是 tabBar 内的按钮 UITabBarButton 被设置了错误的 frame,frame.size 变为 (0, 0) 导致的。
[UITabBar appearance].translucent = NO;
2.iOS 13.0 之后出现bug
(1)一般设置(出现问题选中可以设置 未选中的一直爽默认状态)
tabbar.tintColor = k_main_tab_text_color;
tabbar.unselectedItemTintColor = k_title_color_2B;
上面本人设置了unselectedItemTintColor 但是还是默认颜色
(2)最终解决方案
if (@available(iOS 13.0, *)) {
//这个是操作改变选中未选中的
UITabBarItemAppearance *item_Appearance = [[UITabBarItemAppearance alloc] init];
[item_Appearance.normal setTitleTextAttributes:@{ NSForegroundColorAttributeName:k_title_color_2B,NSFontAttributeName:TEXT_LIT_B_FONT10}];
[item_Appearance.selected setTitleTextAttributes:@{ NSForegroundColorAttributeName:k_main_tab_text_color,NSFontAttributeName:TEXT_LIT_B_FONT10}];
//导航栏其它属性设置
UITabBarAppearance *appearance = [self.tabBar.standardAppearance copy];
appearance.backgroundColor = k_main_tab_bar_color;
appearance.backgroundImage = [UIImage imageNamed:@"tab_bkg_bai"];
//将item赋值过来
appearance.stackedLayoutAppearance = item_Appearance; //
tabbar.standardAppearance =appearance;
//此代码可以改变选中颜色
tabbar.tintColor = k_main_tab_text_color;
if (@available(iOS 15.0, *)) {
tabbar.scrollEdgeAppearance =appearance;
}
}else{
// tabbar.barTintColor = k_main_tab_bar_color;
tabbar.backgroundImage = [UIImage imageNamed:@"tab_bkg_2"];
[[UITabBar appearance] setBackgroundImage:[UIImage imageNamed:@"tab_bkg_2"]];
}