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?
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: "menu@2x.png")!.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal) item2.image = UIImage(named: "play@2x.png")!.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal) }
}
in custom class the code should be like as above... you can set selectedState Image as well....
here is the result..
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.