標籤:
UITabBarController
1 class UITabBarControllerController: UIViewController { 2 3 var titleString:String! 4 5 @IBOutlet var titleLabel:UILabel! 6 7 @IBOutlet var tabBarCtl:UITabBarController! 8 9 10 //返回按鈕事件11 @IBAction func backButtonClick()12 {13 self.navigationController?.popViewControllerAnimated(true)14 }15 16 17 override func viewDidLoad() {18 super.viewDidLoad()19 20 titleLabel.text = titleString21 22 23 // Do any additional setup after loading the view.24 }25 26 override func didReceiveMemoryWarning() {27 super.didReceiveMemoryWarning()28 // Dispose of any resources that can be recreated.29 }30 31 32 /*33 // MARK: - Navigation34 35 // In a storyboard-based application, you will often want to do a little preparation before navigation36 override func prepareForSegue(segue: UIStoryboardSegue!, sender: AnyObject!) {37 // Get the new view controller using segue.destinationViewController.38 // Pass the selected object to the new view controller.39 }40 */41 42 43 //開啟一個新的視圖控制器,由UITabBarController建立44 @IBAction func creatTabBarController()45 {46 self.presentViewController(self.tabBarCtl, animated: true, completion: {47 48 })49 }50 51 //建立代碼UITabBarController52 @IBAction func usedCodeCreatTabBarController()53 {54 //定義第1視圖控制器55 var itemCtl1 = ItemController1()56 57 //定義第2視圖控制器58 var itemCtl2 = ItemController2()59 60 //定義第3視圖控制器61 var itemCtl3 = ItemController3()62 63 //定義第4視圖控制器64 var itemCtl4 = ItemController4()65 66 67 //定義UITabBarController68 69 var newTabBarCtl = UITabBarController()70 71 //添加要管理4的視圖72 newTabBarCtl.addChildViewController(itemCtl1)73 newTabBarCtl.addChildViewController(itemCtl2)74 newTabBarCtl.addChildViewController(itemCtl3)75 newTabBarCtl.addChildViewController(itemCtl4)76 77 //或者,通過setViewControllers方法來一起設定78 newTabBarCtl.setViewControllers([itemCtl1,itemCtl2,itemCtl3,itemCtl4], animated: true)79 80 81 //建立4個UITabBarItem 執行個體82 var barItem1 = UITabBarItem(title: "紅色", image: nil, tag: 11)83 var barItem2 = UITabBarItem(title: "綠色", image: nil, tag: 12)84 var barItem3 = UITabBarItem(title: "藍色", image: nil, tag: 13)85 var barItem4 = UITabBarItem(title: "橘色", image: nil, tag: 14)86 87 //重新設定4個控制的tabBarItem88 itemCtl1.tabBarItem = barItem189 itemCtl2.tabBarItem = barItem290 itemCtl3.tabBarItem = barItem391 itemCtl4.tabBarItem = barItem492 93 94 //推出UITabBarController95 self.presentViewController(newTabBarCtl, animated: true, completion: {96 97 })98 }99 }
iOS開發——UI篇Swift篇&UITabBarController