1. 程式人生 > >Swift下同時建立UITabBarController和UINavigationControlle

Swift下同時建立UITabBarController和UINavigationControlle

//在window上設定視窗為UITabBarController

self.window=UIWindow(frame: UIScreen.mainScreen().bounds) 

self.window!.rootViewController = UITabBarController()

self.window!.makeKeyAndVisible()

return true

//在UITabBarController的.swift檔案中 建立UIViewController,並且包裝成導航控制器

let SY = UIViewController()      //建立

let NV = UINavigationController(rootViewController: SY)    //包裝

//設定導航欄標題

SY.navigationItem.title = "enenenn"

//設定TabBar標題

NV.tabBarItem.title = "首頁"

//新增到TabBar

viewControllers=[NV]   //這行的意思是多個控制器可以以陣列的形式一次新增上去

或者

addChildViewController(NV)

-------------------------------------------------------------

//設定tabBar 欄的背景顏色

self.tabBar.barTintColorUIColor.redColor

()

//設定導航條背景顏色

NV.navigationBar.barTintColor = UIColor.redColor()