iOS开发——UI篇Swift篇&UITabBarController
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 = titleString 21 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: - Navigation 34 35 // In a storyboard-based application, you will often want to do a little preparation before navigation 36 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 //创建代码UITabBarController 52 @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 //定义UITabBarController 68 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个控制的tabBarItem 88 itemCtl1.tabBarItem = barItem1 89 itemCtl2.tabBarItem = barItem2 90 itemCtl3.tabBarItem = barItem3 91 itemCtl4.tabBarItem = barItem4 92 93 94 //推出UITabBarController 95 self.presentViewController(newTabBarCtl, animated: true, completion: { 96 97 }) 98 } 99 }
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。