修改UITabBarItem字体颜色

本文介绍了如何在iOS应用中修改UITabBarItem的字体颜色,包括使用正确的属性名称以兼容不同版本的iOS,并展示了如何设置选中状态的颜色。
  • 修改UITabBarItem下面字体的颜色,如图:

    \

    [[UITabBarItemappearance]setTitleTextAttributes:[NSDictionarydictionaryWithObjectsAndKeys:[UIColorblackColor],UITextAttributeTextColor,nil]forState:UIControlStateNormal];

    [[UITabBarItemappearance]setTitleTextAttributes: [NSDictionarydictionaryWithObjectsAndKeys:[UIColorredColor],UITextAttributeTextColor,nil]forState:UIControlStateSelected];

    这个时候会报警告'UITextAttributeTextColor' is deprecated in iOS 7. The iOS 7 key is 'NSForegroundColorAttributeName

    然后替换一下就可以了,不过NSForegroundColorAttributeName最底支持到ios6.0

    [[UITabBarItemappearance]setTitleTextAttributes:[NSDictionarydictionaryWithObjectsAndKeys:[UIColorblackColor],NSForegroundColorAttributeName,nil]forState:UIControlStateNormal];

    [[UITabBarItemappearance]setTitleTextAttributes: [NSDictionarydictionaryWithObjectsAndKeys:[UIColorredColor],NSForegroundColorAttributeName,nil]forState:UIControlStateSelected];

    以上是改变字体颜色的,图片颜色无法改变,

    [[UITabBarappearance]setTintColor:[UIColorredColor]];

    但是上面这一句就可以改变并设置点击后的图片和文字颜色了。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值