0

Right now, I'm using black/white pngs as my icons, and using tintColor when user selects them. I feel that this is too plain.

I want to use multi-color images (it's selected) and then a grey-scale version of the same image (when it's not selected)

How do I use two images for each TabBar Item?

TIMEX
  • 259,804
  • 351
  • 777
  • 1,080

1 Answers1

1

Create a subclass of your UITabBarController and set the icon images to UITableBarItems in viewDidLoad() of UITabBarController subclass.

override func viewDidLoad() {
    super.viewDidLoad()

    // Do any additional setup after loading the view.

    let tabBar: UITabBar = self.tabBar
    let tabBarItem1: UITabBarItem = tabBar.items![0]
    let tabBarItem2: UITabBarItem = tabBar.items![1]

    tabBarItem1.image = UIImage.init(named: "tab_icon_1_normal")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
    tabBarItem2.image = UIImage.init(named: "tab_icon_2_normal")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)

    tabBarItem1.selectedImage = UIImage.init(named: "tab_icon_1_selected")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
    tabBarItem2.selectedImage = UIImage.init(named: "tab_icon_2_selected")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
}
Jebeom Gyeong
  • 331
  • 2
  • 10