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