0

I am trying to add an icon which is multicolored and when I added the icon as per in the tab bar, it is showing a single color blue, the actual colors of the icon are not visible?

how should I add the colored icon in the tab bar?

  • Change ImageTint : You can check this [answer](https://stackoverflow.com/questions/26835148/change-tab-bar-item-selected-color-in-a-storyboard/29673404#29673404) – Arman_Gorjipoor Nov 06 '19 at 08:49
  • Possible duplicate of [Change tab bar item selected color in a storyboard](https://stackoverflow.com/questions/26835148/change-tab-bar-item-selected-color-in-a-storyboard) – Niki Nov 06 '19 at 08:57
  • @Arman_Gorjipoor how can we place the original image which has multi color –  Nov 06 '19 at 08:57

4 Answers4

3

In assets folder in x-code select your image and in attribute inspector change value of Render As to "Original Image" instead of "Default".

Talha Ahmed
  • 160
  • 1
  • 10
0

This is because in a tab bar all images are displayed with rendering mode set to template, you can override this behavior forcing rendering mode when loading the image:

let yourImage = UIImage(named: "your_image")?.withRenderingMode(.alwaysOriginal)

and then use your image as a tab bar icon.

Maciej Gad
  • 1,701
  • 16
  • 21
0

It is better do this in code like this:

var aViewController: UIViewController = UIViewController()

// This statement is what you need

var myTabBarItem: UITabBarItem = UITabBarItem(title: nil, image: UIImage(named: "YOUR_IMAGE_NAME")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal), selectedImage: UIImage(named: "YOUR_IMAGE_NAME"))
aViewController.tabBarItem = myTabBarItem
0

Don't do it in the storyboard. Try this:

extension UITabBarItem {

    convenience init(title: String, unselected: String, selected: String) {

        let selectedImage = UIImage(named: selected)?.withRenderingMode(.alwaysOriginal)
        let unselectedImage = UIImage(named: unselected)?.withRenderingMode(.alwaysOriginal)

        self.init(title: title, image: unselectedImage, selectedImage: selectedImage)
    }
}

and then in viewDidLoad in your view controller...

tabBarItem = UITabBarItem(title: "My title",
                          unselected: "unselectedIconName",
                          selected: "selectedIconName")
norders
  • 1,160
  • 9
  • 13