简体   繁体   中英

Change Icon Color Tab Bar Controller-SWIFT

I am working in Xcode 6 with SWIFT and have been able to successfully change the color of the text on my tab bar controller, but I cannot get the color to change on the icons themselves. My code below in the AppDelegate:

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {

    UITabBarItem.appearance().setTitleTextAttributes([NSForegroundColorAttributeName: UIColor(red: 239/255, green: 64/255, blue: 54/255, alpha: 1.0)], forState: .Selected)
    UITabBarItem.appearance().setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.whiteColor()], forState: .Normal)

I have a separate class for the navigation controller to change text and color.

You need to set the image on the tab bar item to a UIImage with renderingMode = UIImageRenderingMode.AlwaysTemplate

Then you can set the tintColor on the UITabBar to change the color of the icons and the text simultaneously. You should still be able to override that for the text with the appearance selectors you have created though.

If I recall, UITabBar should set the renderingMode automatically, so try just setting the tintColor first.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM