IOS 8 Tab Bar Item Background Colour

前端 未结 5 819
没有蜡笔的小新
没有蜡笔的小新 2020-11-30 04:11

I\'ve been trying to find the solution to this for the last week, and I have had no luck after trying every possible solution I could find or think of. Every solution I foun

5条回答
  •  独厮守ぢ
    2020-11-30 04:38

    You can call this function from each controller passing self.tabBarController and each color you want.

    Function :

    static func customTabBar(controller: UIViewController?, backgroundColor: String, unselectedColor: String, selectedColor: String) {
            if let tabBarController = controller as? UITabBarController {
                tabBarController.tabBar.barTintColor = UIColor(hex: backgroundColor)
                tabBarController.tabBar.tintColor = UIColor(hex: selectedColor)
                tabBarController.tabBar.isTranslucent = false
                tabBarController.tabBar.selectedItem?.setTitleTextAttributes([NSAttributedString.Key.foregroundColor:UIColor(hex: selectedColor)], for: UIControl.State.selected)
                if #available(iOS 10.0, *) {
                    tabBarController.tabBar.unselectedItemTintColor = UIColor(hex: unselectedColor)
                } else {
                    // Fallback on earlier versions
                }
            }
        }
    

提交回复
热议问题