UITabbarController 简单使用

class TabbarVC: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
    }

    /// 添加子控制器
    private func addChildVC(childVC: UIViewController, childTitle: String, imageName: String, selectedImageName:String) {
        let navigation = UINavigationController(rootViewController: childVC)
        
        navigation.navigationBar.tintColor = UIColor.black  //item 字体颜色
        navigation.navigationBar.barTintColor = UIColor.white
        navigation.navigationBar.shadowImage = UIImage.init()
        
        let dict:NSDictionary = [NSAttributedStringKey.foregroundColor: UIColor.black,
                                 NSAttributedStringKey.font : UIFont.boldSystemFont(ofSize: 18)
        ]
        
        //标题颜色
        navigation.navigationBar.titleTextAttributes = dict as? [NSAttributedStringKey : Any]
        childVC.title = childTitle
        childVC.tabBarItem.tag = 1
        
        childVC.tabBarItem.image = UIImage(named: imageName)?.withRenderingMode(.alwaysOriginal)
        childVC.tabBarItem.selectedImage = UIImage(named: selectedImageName)?.withRenderingMode(.alwaysOriginal)
        self.addChildViewController(navigation)
    }
}

你可能感兴趣的:(UITabbarController 简单使用)