更新了xcode11以后,发现之前用的第三方tabbar存在很大的问题。跳转到二级页面以后返回,tabbar的标题看不见了,因此改回系统的。
#import "HSMainTabBarController.h"
@interface HSMainTabBarController ()
@end
@implementation HSMainTabBarController
+ (HSMainTabBarController *)shareInstance
{
static HSMainTabBarController *vc = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
vc = [[self alloc] init];
});
return vc;
}
- (void)viewDidLoad {
[super viewDidLoad];
[self initTabbar];
// [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(editSelectedIndex) name:Notify_SendDynamicSuccess object:nil];
}
- (void)initTabbar {
// HSShopLibraryViewController *homeVC = [[HSShopLibraryViewController alloc] init];
// HSDynamicViewController *dynamicVC = [[HSDynamicViewController alloc] init];
HSShopLibrary_VC *homeVC = [[HSShopLibrary_VC alloc] init];
HSSmallChatVC *chatVC = [[HSSmallChatVC alloc] init];
HSReceiveGuestsVC *receiveVC = [[HSReceiveGuestsVC alloc]init];
HSFIndViewController *findVC = [[HSFIndViewController alloc] init];
HSMyViewController *myVC = [[HSMyViewController alloc] init];
// [self addChildViewController:dynamicVC title:@"动态" normalImage:@"dynamic_s" selectedImage:@"dynamic_n"];
[self addChildViewController:homeVC title:@"相册" normalImage:@"library_s" selectedImage:@"library_n"];
[self addChildViewController:chatVC title:@"汇客" normalImage:@"dynamic_s" selectedImage:@"dynamic_n"];
[self addChildViewController:receiveVC title:@"获客" normalImage:@"receiveGuests_s" selectedImage:@"receiveGuests_n"];
[self addChildViewController:findVC title:@"发现" normalImage:@"find_s" selectedImage:@"find_n"];
[self addChildViewController:myVC title:@"我的" normalImage:@"mine_s" selectedImage:@"mine_n"];
}
- (void)addChildViewController:(UIViewController *)viewConroller title:(NSString *)title normalImage:(NSString *)normalImage selectedImage:(NSString *)selectedImage
{
// 设置选中的字体颜色,否则返回之后会变回默认字体颜色
self.tabBar.tintColor = HEXCOLOR(0x49A3C9);
viewConroller.title = title;
viewConroller.tabBarItem.image = [[UIImage imageNamed:normalImage] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
viewConroller.tabBarItem.selectedImage = [[UIImage imageNamed:selectedImage]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
// [viewConroller.tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName:HEXCOLOR(0x49A3C9)} forState:UIControlStateSelected];
[viewConroller.tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName:HEXCOLOR(0x323232)} forState:UIControlStateNormal];
HSBaseNavigationController *baseNav = [[HSBaseNavigationController alloc] initWithRootViewController:viewConroller];
[baseNav.navigationBar setBarTintColor:COLOR_NAV_BG];
[self addChildViewController:baseNav];
}
最后发现还是有问题,跳转二级页面返回之后,tabbar标题颜色变成了系统默认的颜色,
后面发现这样设置还是有问题[viewConroller.tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName:HEXCOLOR(0x49A3C9)} forState:UIControlStateSelected];
最后试了使用self.tabBar.tintColor = HEXCOLOR(0x49A3C9);
完美解决!!!
(记录开发中一些小问题,本人经验不够,记性不好)