TabBarItem change the text color failure

  • A recent study Swift, from the projects, found tabBarItem not selected text color does not work, the system default is gray
UITabBarItem.appearance().setTitleTextAttributes([NSAttributedString.Key.foregroundColor: UIColor.green], for: .selected)
UITabBarItem.appearance().setTitleTextAttributes([NSAttributedString.Key.foregroundColor: UIColor.red], for: .normal)

Asked the next, was said to be iOS13 problem is not specific iOS question 13, he did not go Certification

solution

iOS under 13 UITabBarItem.appearance().setTitleTextAttributes([NSAttributedString.Key.foregroundColor: UIColor.red], for: .normal)property is set to normal state already does not work, Apple put out a few blind through this, it is not uncomfortable

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

or

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

Guess you like

Origin www.cnblogs.com/gchlcc/p/12564110.html