如何更新或重新加载UITabBarItem上的文本颜色?
只有在我终止该应用程序并重新打开后,它才会运行。然后,它将刷新UITabBarItem上的textColor
Swift 5.1,iOS 12
func handleRefreshForTabBar() {
DispatchQueue.main.async {
//Background
self.view.backgroundColor = Theme.current.generalBackground
//Images
self.tabBar.tintColor = Theme.current.tabTintColor
//Bar
self.tabBar.barTintColor = Theme.current.tabBarTintColor
}
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
handleRefreshForTabBar()
UITabBarItem.appearance().setTitleTextAttributes([NSAttributedString.Key.foregroundColor: Theme.current.tabBarSelectedTextColor],for: .selected)
UITabBarItem.appearance().setTitleTextAttributes([NSAttributedString.Key.foregroundColor: Theme.current.tabBarNormalTextColor],for: .normal)
}
我尝试过的选项
tabBar.setNeedsDisplay()
tabBar.setNeedsLayout()
view.reloadInputViews()
view.setNeedDisplay()
view.setNeedsLayout()
我的TabBar是我的rootVC