Changing tab bar item image and text color iOS

前端 未结 22 1161
说谎
说谎 2020-12-02 06:10

Here is my tab bar:

\"enter

The following image shows the program being run an

22条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-02 06:44

    For Swift 4.0, it's now changed as:

    tabBarItem.setTitleTextAttributes([NSAttributedStringKey.foregroundColor: UIColor.gray], for: .normal)
    tabBarItem.setTitleTextAttributes([NSAttributedStringKey.foregroundColor: UIColor.blue], for: .selected)
    

    You don't have to subclass the UITabBarItem if your requirement is only to change the text color. Just put the above code inside your view controller's viewDidLoad function.

    For global settings change tabBarItem to UITabBarItem.appearance().

提交回复
热议问题