1. 程式人生 > >IOS初學-選項卡控制器

IOS初學-選項卡控制器

選項卡控制器

首先需要建立兩個檢視

class FirstSubViewController: UIViewController {
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
        self.title="111111111"
        self.tabBarItem.image=UIImage(named: "Tab")
        self.view.backgroundColor=UIColor.brown;
    }
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
}
class SecondSubViewController: UIViewController {
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
        self.view.backgroundColor=UIColor.purple;
        self.title="222222"
        self.tabBarItem.image=UIImage(named: "Tab2");
    }
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
}

建立完成之後我們需要在AppDelegate.swift中修改程式的入口application() 之後執行就可以看到實現效果了

	 let view=UITabBarController();
        let firstController = FirstSubViewController();
        let secondController = SecondSubViewController();
        view.viewControllers=[firstController,secondController];
        view.view.backgroundColor=UIColor.gray;
        self.window?.rootViewController=view;