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

本文介绍了在iOS应用开发中,如何根据不同选中项改变TabBar的颜色,提供了两种方法:一是使用图片代替文字,二是通过代理方法动态设置颜色。

   转载请注明出处!!!

在开发中常常遇到带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);
    }
}

 

转载于:https://www.cnblogs.com/weicyNo-1/p/7650581.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值