0

I want to change the UI Tab Bar Icon colour to the values: Red: 0.75, Green: 1.0, Blue: 1.0, Alpha: 1.0 and to white when the Icon is not selected.

Till now I thought this is how you do it:

UITabBarItem.appearance().finishedSelectedImage([NSForegroundColorAttributeName: UIColor(red: 0.75, green: 1.0, blue: 1.0, alpha: 1.0)], forState: UIControlState.Selected)

    UITabBarItem.appearance().finishedUnselectedImage([NSForegroundColorAttributeName: UIColor.whiteColor()], forState: UIControlState.Normal)

The code above is in my delegate.

Now I have put this code:

import UIKit

class UITabBarViewController: UIViewController {

override func viewDidLoad() {
    super.viewDidLoad()

    var testImage = UIImage(named: "22274")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysTemplate)
    testImageView.tintColor = UIColor.redColor()
    testImageView.image = testImage

    // Do any additional setup after loading the view.
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}



}

Into my tab bar view controller cocco touch file. I don't know why I'm getting an error still

Arafat Qureshi
  • 101
  • 4
  • 11

3 Answers3

0

I had traverse all the sub-controllers of UITabbarController, and then set the TabBarItem's color or tint color of each controller, it does work.

ImWH
  • 820
  • 1
  • 7
  • 20
0

If the tabbaritem has an image, you can set its color by:

var testImage = UIImage(named: "someImageName")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysTemplate)
testImageView.tintColor = UIColor.redColor()
testImageView.image = testImage
Dániel Nagy
  • 11,815
  • 9
  • 50
  • 58
0

I think It's not available to make it, you can just get an image in the color you want and use it in the UITabbar but regarding to change the all TabBar colors you can use the below in your AppDelegate in Func:

didFinishLaunchingWithOptions

Lines To be added:

UITabBar.appearance().barTintColor = #colorLiteral(red: 0.2000651062, green: 0.1960035861, blue: 0.2000851929, alpha: 1)

UITabBar.appearance().tintColor = #colorLiteral(red: 0.2000651062, green: 0.1960035861, blue: 0.2000851929, alpha: 1)

UITabBar.appearance().unselectedItemTintColor = #colorLiteral(red: 0.7415059209, green: 0.5448099971, blue: 0.5051562786, alpha: 1) 

Note: You can change colors depending on your App

Check the image: https://i.stack.imgur.com/wESVH.png

and have a happy coding day

Menaim
  • 937
  • 7
  • 28