Advertisement
Guest User

Untitled

a guest
Jun 24th, 2019
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.77 KB | None | 0 0
  1. window = UIWindow(frame: UIScreen.main.bounds)
  2. window?.rootViewController = TabBarViewController()
  3. window?.makeKeyAndVisible()
  4.  
  5. class TabBarViewController: UITabBarController {
  6.  
  7. override func viewDidLoad() {
  8. super.viewDidLoad()
  9.  
  10. // Navigation Tab
  11. let navVC = NavigationViewController()
  12.  
  13. // Departure Tab
  14. let depVC = DeparturesViewController()
  15.  
  16. // Settings Tab
  17. let setVC = SettingsViewController()
  18.  
  19. self.viewControllers = [
  20. createNavigationController(title: "Navigation", rootViewController: navVC, imageName: "map"),
  21. createNavigationController(title: "Abfahrten", rootViewController: depVC, imageName: "station"),
  22. createNavigationController(title: "Einstellungen", rootViewController: setVC, imageName: "user"),
  23. ]
  24. }
  25.  
  26. private func createNavigationController(title: String, rootViewController: UIViewController, imageName: String) -> UINavigationController {
  27.  
  28. rootViewController.title = title
  29. let nc = UINavigationController(rootViewController: rootViewController)
  30. nc.title = title
  31. nc.view.backgroundColor = .white
  32. nc.navigationBar.prefersLargeTitles = true
  33. nc.navigationController?.navigationItem.largeTitleDisplayMode = .always
  34. nc.tabBarItem.image = UIImage(named: imageName)?.withRenderingMode(UIImage.RenderingMode.alwaysTemplate)
  35. return nc
  36. }
  37.  
  38. override func viewWillAppear(_ animated: Bool) {
  39. self.selectedIndex = 0
  40. }
  41.  
  42. }
  43.  
  44. class NavigationViewController: UIViewController {
  45.  
  46. override func viewDidLoad() {
  47. super.viewDidLoad()
  48. self.view.backgroundColor = .red
  49. }
  50.  
  51. }
  52.  
  53. override func viewWillAppear(_ animated: Bool) {
  54. self.selectedIndex = 0
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement