Swift UITabBarController:UITabBarItem更新或重新加载它
如何更新或重新加载UItabaritem上的文本颜色 只有在我关闭应用程序并重新打开时,它才会出现。然后它将刷新UITabBarItem上的文本颜色 Swift 5.1,iOS 12Swift UITabBarController:UITabBarItem更新或重新加载它,swift,uitabbarcontroller,uitabbar,uitabbaritem,Swift,Uitabbarcontroller,Uitabbar,Uitabbaritem,如何更新或重新加载UItabaritem上的文本颜色 只有在我关闭应用程序并重新打开时,它才会出现。然后它将刷新UITabBarItem上的文本颜色 Swift 5.1,iOS 12 func handleRefreshForTabBar() { DispatchQueue.main.async { //Background self.view.backgroundColor = Theme.current.generalB
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这并不能直接回答你的问题,但你有没有研究过这个:?专门使用颜色集资源处理明暗界面?问题是我选择退出systemColor。。。所以我是手动操作的,所以我的应用程序不会检测到用户的iphone外观,我也有我的颜色资源,但我确信它不会检测任何颜色的systemColor或colorAssets,无论是浅颜色还是深颜色。
/// Function that makes the tab bar refresh itself. Specially important for refreshing light or dark mode styles
func handleRefreshForTabBar() {
DispatchQueue.main.async {
//Set up the same color as the NavBar to avoid bugs
self.view.backgroundColor = Theme.current.generalBackground
//Images
self.tabBar.tintColor = Theme.current.tabTintColor
//Bar
self.tabBar.barTintColor = Theme.current.tabBarTintColor
self.tabBar.items!.forEach { (item) in
item.setTitleTextAttributes([NSAttributedString.Key.foregroundColor: Theme.current.tabBarSelectedTextColor], for: .selected)
item.setTitleTextAttributes([NSAttributedString.Key.foregroundColor: Theme.current.tabBarNormalTextColor], for: .normal)
}
}
}