UITabbar标题颜色问题

更新了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);

完美解决!!!

(记录开发中一些小问题,本人经验不够,记性不好)

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值