完成了所有畫面後,需要切換畫面,這裡使用的是Tabbar。
使用Tabbar之前,要先把每個畫面處理一下,然後放進Tabbar陣列裡。
let rootVC1 = AlarmViewController(nibName: String(describing: AlarmViewController.self), bundle: nil)
let navigationVC1 = UINavigationController(rootViewController: rootVC1)
let rootVC2 = StopWatchViewController(nibName: String(describing: StopWatchViewController.self), bundle: nil)
let navigationVC2 = UINavigationController(rootViewController: rootVC2)
let rootVC3 = WorldClockViewController(nibName: String(describing: WorldClockViewController.self), bundle: nil)
let navigationVC3 = UINavigationController(rootViewController: rootVC3)
let rootVC4 = TimerViewController(nibName: String(describing: TimerViewController.self), bundle: nil)
let navigationVC4 = UINavigationController(rootViewController: rootVC4)
let MyTabBar = UITabBarController()
let AlarmVC = navigationVC1
AlarmVC.tabBarItem.image = UIImage(systemName: "clock")
AlarmVC.tabBarItem.title = "鬧鐘"
let StopWatchVC = navigationVC2
StopWatchVC.tabBarItem.image = UIImage(systemName: "stopwatch")
StopWatchVC.tabBarItem.title = "碼表"
let WorldClockVC = navigationVC3
WorldClockVC.tabBarItem.image = UIImage(systemName: "globe")
WorldClockVC.tabBarItem.title = "世界時鐘"
let TimerVC = navigationVC4
TimerVC.tabBarItem.image = UIImage(systemName: "timer")
TimerVC.tabBarItem.title = "計時器"
MyTabBar.viewControllers = [AlarmVC, StopWatchVC, WorldClockVC, TimerVC]
MyTabBar.selectedIndex = 0
}
今天到這裡就結束啦,明天就能開始做別的東西了。