Swift 关于Tabbar的渲染以及基本设置

2018-12-12  本文已影响24人  xieyinghao
 let HomeVC = HomeViewController()
        HomeVC.title = titleArray[0] as? String;
        let na1 = UINavigationController(rootViewController: HomeVC)
        
        let projectVC = ProjectViewController()
        projectVC.title = titleArray[1] as?String;
        let na2 = UINavigationController(rootViewController: projectVC)
        
        let findVc = FindViewController();
        findVc.title = titleArray[2] as? String
        let na3 = UINavigationController(rootViewController: findVc)
        
        let myVc = MyViewController()
        myVc.title = (titleArray[3] as! String)
        let na4 = UINavigationController(rootViewController: myVc)
        
        self.viewControllers = [na1,na2,na3,na4]
        
        
        // 设置标题,未选中状态图标,选中状态图标
        let moreImage1 = UIImage(named: "精选")?.withRenderingMode(.alwaysOriginal)
        let moreSelectImage1 = UIImage(named:"精选交互")?.withRenderingMode(.alwaysOriginal)
        let barItem01 = UITabBarItem(title: "精选", image: moreImage1, selectedImage: moreSelectImage1)
        na1.tabBarItem = barItem01
        
        let moreImage2 = UIImage(named: "投资")?.withRenderingMode(.alwaysOriginal)
        let moreSelectImage2 = UIImage(named:"投资交互")?.withRenderingMode(.alwaysOriginal)
        let barItem02 = UITabBarItem(title: "投资", image: moreImage2, selectedImage: moreSelectImage2)
        na2.tabBarItem = barItem02
        
        let moreImage3 = UIImage(named: "发现")?.withRenderingMode(.alwaysOriginal)
        let moreSelectImage3 = UIImage(named:"发现交互")?.withRenderingMode(.alwaysOriginal)
        let barItem03 = UITabBarItem(title: "发现", image: moreImage3, selectedImage: moreSelectImage3)
        na3.tabBarItem = barItem03
        
        
        let moreImage4 = UIImage(named: "我的")?.withRenderingMode(.alwaysOriginal)
        let moreSelectImage4 = UIImage(named:"我的交互")?.withRenderingMode(.alwaysOriginal)
        let barItem04 = UITabBarItem(title: "我的", image: moreImage4, selectedImage: moreSelectImage4)
        na4.tabBarItem = barItem04

        self.tabBar.tintColor = UIColor.orange
上一篇下一篇

猜你喜欢

热点阅读