Swfit 學習 簡單UI

//創建window

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


//設置根VC

self.window!.rootViewController = ViewController()


//創建一個btn

var btn = UIButton (frame:CGRect(x: 100, y: 100, width: 100, height: 100))


// 設置背景顏色

   btn.backgroundColor = UIColor.yellowColor();

        

 // 將添加到我們的vc上

self.window!.rootViewController!.view.addSubview(btn)

        

self.window!.makeKeyAndVisible()



//創建window 

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

        //創建VC

        let  vc = ViewController()

        let oneVc = OnrViewController()

        let two = TwoViewController()

        let three = ThreeViewController()

        let four = FourViewController()

        

        //設置背景顏色

        vc.view.backgroundColor = UIColor.redColor()

        vc.title = "SwiftDemo"

        vc.tabBarItem.title = vc.title

        

        oneVc.title = "2"

        oneVc.view.backgroundColor = UIColor.greenColor()

        oneVc.tabBarItem.title = oneVc.title

        

        two.title = "3"

        two.view.backgroundColor = UIColor.blueColor()

        two.tabBarItem.title = two.title

        

        three.title = "4"

        three.view.backgroundColor = UIColor.brownColor()

        three.tabBarItem.title = three.title

        

        four.title = "123"

        four.view.backgroundColor = UIColor.purpleColor()

        four.tabBarItem.title = four.title

        //創建nav

        let nav1 = UINavigationController(rootViewController:vc)

        let nav2 = UINavigationController(rootViewController:oneVc)

        let nav3 = UINavigationController(rootViewController:two)

        let nav4 = UINavigationController(rootViewController:three)

        let nav5 = UINavigationController(rootViewController:four)

        

        let tabber = UITabBarController()

        tabber.tabBar.tintColor = UIColor.whiteColor()

        tabber.viewControllers = [nav1,nav2,nav3,nav4,nav5]

        

        //設置window的根vc

        self.window!.rootViewController = tabber

        self.window!.makeKeyAndVisible()



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章