Here is a sample of creating your own UITabBarController and customise tab bar behaviour on ios. not only customising tint colour of icon or icon itself but also adding more functionality when switching tab, it required to make your own class inheriting UITabBarController but you want to use the views and tab bar controller scene from story board.
- start from tab application default
- remove segure from story board connected to views from tab bar scene
- set story boad ID to each scene which would be navigated by the tab bar. (FirstView, SecondView for example)
- create a new class MyTabBarController
```
class MyTabBarController: UITabBarController, UITabBarControllerDelegate {var firstViewController: FirstViewController!
var secondViewController: SecondViewController!override func viewDidLoad() {
super.viewDidLoad()
self.delegate = self
firstViewController = storyboard?.instantiateViewController(withIdentifier: "FirstView") as? FirstViewController
secondViewController = storyboard?.instantiateViewController(withIdentifier: "SecondView") as? SecondViewController
firstViewController.tabBarItem.image = UIImage(named: "customFirstImage")
secondViewController.tabBarItem.image = UIImage(named: "customFirstImage")viewControllers = [firstViewController, secondViewController] selectedIndex = 0
}/*// In a storyboard-based application, you will often want to do a little preparation before navigation
// MARK: - Navigation
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
// Get the new view controller using segue.destination.
// Pass the selected object to the new view controller.
}
*/
}
``` - set MyTabBarController as the class of tab bar controller in the story board
0 件のコメント:
コメントを投稿