UITabBarController
class UITabBarControllerController: UIViewController { var titleString:String! @IBOutlet var titleLabel:UILabel! @IBOutlet var tabBarCtl:UITabBarController! //返回按钮事件 @IBAction func backButtonClick() { self.navigationController?.popViewControllerAnimated(true) } override func viewDidLoad() { super.viewDidLoad() titleLabel.text = titleString // Do any additional setup after loading the view. } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } /* // MARK: - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation override func prepareForSegue(segue: UIStoryboardSegue!, sender: AnyObject!) { // Get the new view controller using segue.destinationViewController. // Pass the selected object to the new view controller. } */ //打开一个新的视图控制器,由UITabBarController创建 @IBAction func creatTabBarController() { self.presentViewController(self.tabBarCtl, animated: true, completion: { }) } //创建代码UITabBarController @IBAction func usedCodeCreatTabBarController() { //定义第1视图控制器 var itemCtl1 = ItemController1() //定义第2视图控制器 var itemCtl2 = ItemController2() //定义第3视图控制器 var itemCtl3 = ItemController3() //定义第4视图控制器 var itemCtl4 = ItemController4() //定义UITabBarController var newTabBarCtl = UITabBarController() //添加要管理4的视图 newTabBarCtl.addChildViewController(itemCtl1) newTabBarCtl.addChildViewController(itemCtl2) newTabBarCtl.addChildViewController(itemCtl3) newTabBarCtl.addChildViewController(itemCtl4) //或者,通过setViewControllers方法来一起设置 newTabBarCtl.setViewControllers([itemCtl1,itemCtl2,itemCtl3,itemCtl4], animated: true) //创建4个UITabBarItem 实例 var barItem1 = UITabBarItem(title: ) var barItem2 = UITabBarItem(title: ) var barItem3 = UITabBarItem(title: ) var barItem4 = UITabBarItem(title: ) //重新设置4个控制的tabBarItem itemCtl1.tabBarItem = barItem1 itemCtl2.tabBarItem = barItem2 itemCtl3.tabBarItem = barItem3 itemCtl4.tabBarItem = barItem4 //推出UITabBarController self.presentViewController(newTabBarCtl, animated: true, completion: { }) } }