UITabBarController: UITabBarItem 更新它或重新加载它

UITabBarController: UITabBarItem Updating it or Reloading it

如何更新或重新加载 UITabBarItem 上的文本颜色?

它会,只有我杀死应用程序并再次打开。然后它将刷新 UITabBarItem

上的 textColor

Swift5.1,iOS12

   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

 /// 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)
                    }

                }
    }