How to change tab bar item text color

前端 未结 12 1978
没有蜡笔的小新
没有蜡笔的小新 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:18

    This is easy , simply subclass UITabBarItem and assign it to be the class of your tab bar item in either storyboard or code. The below works perfectly for me.

    import UIKit
    
    class PPTabBarItem: UITabBarItem {
        required init?(coder aDecoder: NSCoder) {
            super.init(coder: aDecoder)
            commonInit()
        }
        override init() {
            super.init()
            commonInit()
        }
    
        func commonInit() {
            self.setTitleTextAttributes([NSFontAttributeName: UIFont.systemFontOfSize(13), NSForegroundColorAttributeName:UIColor.blackColor()], forState: UIControlState.Normal)
    
            self.setTitleTextAttributes([NSFontAttributeName: UIFont.systemFontOfSize(13), NSForegroundColorAttributeName:UIColor.yellowColor()], forState: UIControlState.Selected)
        }
    }
    

    skywinder's solution is good but it triggers global scope.

提交回复
热议问题