Reputation: 92
I've created a tab bar controller and embedded several view controllers in it. I then try to set a specific tab bar item in a corresponding swift file for that view. Problem is that I am changing the item by overriding the "viewDidLoad" function. So it only updates after the user has touched that item. What be a better approach to changing storyboard tab bar items using swift?
Upvotes: 0
Views: 951
Reputation: 104
there you can access all the TabItems and change their text/images before a ViewController get loaded.
class CustomTabBarController: UITabBarController {
override func viewDidLoad() {
super.viewDidLoad()
let allItems:[AnyObject] = self.tabBar.items!
var item1:UITabBarItem = allItems[0] as! UITabBarItem
var item2:UITabBarItem = allItems[1] as! UITabBarItem
item1.image = UIImage(named: "[email protected]")!.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
item2.image = UIImage(named: "[email protected]")!.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
}
}
in custom class the code should be like as above... you can set selectedState Image as well....
here is the result..
Upvotes: 1