0

I am trying to create custom tab bar controller in UIStoryboard in iOS 8 with swift (objective-c also okay). So, I plan to use this code.

let item0: UITabBarItem = UITabBarController().tabBar.items[0] as UITabBarItem
item0.setFinishedSelectedImage(selectedImage0, withFinishedUnselectedImage: unselectedImage0)

However, problem is that setFinishedSelectedImage is no longer supported and I see this error. How shall I implement?

APIs deprecated as of iOS 7 and earlier are unavailable in Swift

modusCell
  • 13,151
  • 9
  • 53
  • 80
Khant Thu Linn
  • 5,905
  • 7
  • 52
  • 120
  • possible duplicate of [UITabBarItem setFinishedSelectedImage: deprecated in iOS7](http://stackoverflow.com/questions/19563193/uitabbaritem-setfinishedselectedimage-deprecated-in-ios7) – Robotic Cat Aug 09 '14 at 09:19

1 Answers1

7

I don't have Xcode 6 to test this so CODE NOT TESTED but I expect something similar to this in Swift:

var selectedImage0 : UIImage = UIImage(named:"selectedImage0.png").imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
self.navigationController.tabBarItem.selectedImage = selectedImage0

To get the first tabBarItem I would expect something similar to the follow but again CODE NOT TESTED:

// self.yourTabBarController is an IBOutlet to your UITabBar controller
let tabBar = self.yourTabBarController.tabBar 

// UITabBar Items are an array in order (0 is the first item)
let tabItems = tabBar.items as [UITabBarItem]
tabItems[0].title = "First"
tabItems[0].selectedImage = selectedImage0
tabItems[1].title = "Second"
tabItems[1].selectedImage = selectedImage1
/*
etc...
*/
Robotic Cat
  • 5,899
  • 4
  • 41
  • 58