TabBarItem修改文字颜色失效


  • 最近在学习Swift, 起了个项目, 发现了tabBarItem未选中状态文字的颜色不起作用了, 默认的是系统的灰色
UITabBarItem.appearance().setTitleTextAttributes([NSAttributedString.Key.foregroundColor: UIColor.green], for: .selected)
UITabBarItem.appearance().setTitleTextAttributes([NSAttributedString.Key.foregroundColor: UIColor.red], for: .normal)

问了下, 有人说是iOS13的问题, 具体是不是iOS 13的问题, 自己没有去认证

解决方案

iOS 13下 UITabBarItem.appearance().setTitleTextAttributes([NSAttributedString.Key.foregroundColor: UIColor.red], for: .normal)设置normal状态的属性已经不起作用了, 苹果这通瞎几把搞, 不难受吗

tabBar.tintColor = UIColor.blue
// 通过UITabBar.appearance() 点不出unselectedItemTintColor属性, 可以直接硬敲
// UITabBar.appearance().unselectedItemTintColor = UIColor.red
tabBar.unselectedItemTintColor = UIColor.red

或者

UITabBarItem.appearance().setTitleTextAttributes([NSAttributedString.Key.foregroundColor: UIColor.green], for: .selected)
tabBar.unselectedItemTintColor = UIColor.red


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM