iOS開發——UI篇Swift篇&UITabBarController

來源:互聯網
上載者:User

標籤:

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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.