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

posted @ 2020-03-25 09:41  Chaos_G  阅读(1995)  评论(0编辑  收藏  举报