tabBar选择不同item设置标题不同颜色

   转载请注明出处!!!

在开发中常常遇到带tabBar的应用,这些应用一般都是只有一个选中颜色,但在开发中也会遇到选择不同item选中颜色不一致的情况,这时要如何解决呢?
方法一:不设置item title 全让UI切成图片,这时只要我们设置不同的图片即可。
方法二:再点击item的代理方法中设置不同的tintcolor。

- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController{
    
    // 修改tintcolor
    if (tabBarController.selectedIndex == 0) {
        tabBarController.tabBar.tintColor = RGB(69,171,255);
    } else if (tabBarController.selectedIndex == 1) {
        tabBarController.tabBar.tintColor = RGB(171,96,203);
    } else if (tabBarController.selectedIndex == 2) {
        tabBarController.tabBar.tintColor = RGB(252,114,177);
    } else {
        tabBarController.tabBar.tintColor = RGB(255,218,0);
    }
}

 

posted @ 2017-10-11 14:58  weicy  阅读(424)  评论(0编辑  收藏  举报