swift-tabbar

swift创建tabbar

第一步:创建布局

window = UIWindow(frame: UIScreen.main.bounds)
window?.rootViewController = TabBarViewController()
window?.makeKeyAndVisible()

第二步:创建vc

let  MainVC  = FirstViewController()
        MainVC.title = "首页"
        let MainNav = UINavigationController(rootViewController:MainVC)
        MainNav.tabBarItem.title = "首页"
        MainNav.tabBarItem.image = UIImage(named:"tarbar1_no")
        MainNav.tabBarItem.selectedImage = UIImage(named:"tarbar1_yes")
        
        let  ClassVC  = SecondViewController()
        ClassVC.title = "分类"
        let ClassNav = UINavigationController(rootViewController:ClassVC)
        ClassNav.tabBarItem.title = "分类"
        ClassNav.tabBarItem.image = UIImage(named:"tarbar2_no")
        ClassNav.tabBarItem.selectedImage = UIImage(named:"tarbar2_yes")
        
        let  CartVC  = ThirdViewController()
        CartVC.title = "购物车"
        let CartNav = UINavigationController(rootViewController:CartVC)
        CartNav.tabBarItem.title = "购物车"
        CartNav.tabBarItem.image = UIImage(named:"tarbar3_no")
        CartNav.tabBarItem.selectedImage = UIImage(named:"tarbar3_yes")
        let  MyVC  = FourViewController()
        MyVC.title = "我的"
        let MyNav = UINavigationController(rootViewController:MyVC)
        MyNav.tabBarItem.title = "我的"
        MyNav.tabBarItem.image = UIImage(named:"tarbar4_no")
        MyNav.tabBarItem.selectedImage = UIImage(named:"tarbar4_yes")
        
        // 添加工具栏
        items = [MainNav,ClassNav,CartNav,MyNav]
        self.viewControllers = items as? [UIViewController]
      
        //tabBar 底部工具栏背景颜色 (以下两个都行)
        self.tabBar.barTintColor = UIColor.clear
        self.tabBar.backgroundColor = UIColor.white

//这两行代码非常重要需要添加上
//tabBar 底部工具栏背景颜色 (以下两个都行)
self.tabBar.barTintColor = UIColor.clear
self.tabBar.backgroundColor = UIColor.white

demo点击下载

你可能感兴趣的:(swift-tabbar)