ios UITabBarController 一般使用代码

97 阅读1分钟
class IndexVController : UITabBarController {

    override func viewDidLoad() {

        super.viewDidLoad()

        initTab()

        UITabBar.appearance().tintColor = UIColor.red.withAlphaComponent(0.5)

    }

    func initTab(){

        // 每个tab 对应的页面
        let home = HomeVCController()
        // 每个tab 对应的title 与 图片
        home.tabBarItem = UITabBarItem(title: "主页", image: UIImage(named: "home_tabbar_night_32x32_"), selectedImage: UIImage(named: "home_tabbar_press_32x32_"))

        let home1 = HomeVCController()
        home1.tabBarItem = UITabBarItem(title: "主页", image: UIImage(named: "home_tabbar_night_32x32_"), selectedImage: UIImage(named: "home_tabbar_press_32x32_"))
        
        //对应的页面设置给TabBar 这里不能写相同的 相同的只展示一个
        **self**.viewControllers = [home, home1, home, home, home]

    }

}