iOS swift之UITabBarController的使用

  1. 在AppDelegate里面加2行代码,变成这样
    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        // Override point for customization after application launch.
        let root  = RootTabBarController()
        self.window?.rootViewController=root
        return true
    }
  1. 定义RootTabBarController
class RootTabBarController: UITabBarController {
    override func viewDidLoad() {
        super.viewDidLoad()
        
        creatSubViewControllers()
    }
    
    func creatSubViewControllers(){
        let v1  = FirstViewController ()
        let item1 : UITabBarItem = UITabBarItem (title: "第一页面", image: UIImage(named: "home"), selectedImage: UIImage(named: "home_1"))
        v1.tabBarItem = item1
        
        let v2 = SecondViewController()
        let item2 : UITabBarItem = UITabBarItem (title: "第二页面", image: UIImage(named: "favor"), selectedImage: UIImage(named: "favor_1"))
        v2.tabBarItem = item2
        
        let v3 = ThirdViewController()
        let item3 : UITabBarItem = UITabBarItem (title: "第三页面", image: UIImage(named: "me"), selectedImage: UIImage(named: "me_1"))
        v3.tabBarItem = item3
        
        let tabArray = [v1, v2, v3]
        self.viewControllers = tabArray
    }
}
  1. 上面2不就好了,是不是很简单 ~~

推荐阅读更多精彩内容