How to change tab bar item text color

前端 未结 12 1960
没有蜡笔的小新
没有蜡笔的小新 2020-12-13 05:36

\"enter

How can I change the color of \"More..\" text in tabbar to match with its icon

12条回答
  •  离开以前
    2020-12-13 06:22

    Swift 5.1 + iOS 12.4 & iOS 13:

    /// Subclass of `UITabBarController` that is used to set certain text colors for tab bar items.
    class TabBarController: UITabBarController {
    
        override func viewWillAppear(_ animated: Bool) {
            super.viewWillAppear(animated)
            if let items = tabBar.items {
                // Setting the title text color of all tab bar items:
                for item in items {
                    item.setTitleTextAttributes([.foregroundColor: UIColor.black], for: .selected)
                    item.setTitleTextAttributes([.foregroundColor: UIColor.lightGray], for: .normal)
                }
            }
        }
    }
    

提交回复
热议问题