7.4、精简分栏控制器

import UIKit

class TabBarViewController: UITabBarController {

override func viewDidLoad() {
    super.viewDidLoad()
    self.view.backgroundColor = UIColor.red

// self.delegate = self
self.setUp()
}
func setUp() {
self.addChileViewControllers(UINavigationController(rootViewController: OneViewController()), "tabbar01_normal","tabbar01_selected", "首页")
self.addChileViewControllers(UINavigationController(rootViewController: TwoViewController()), "tabbar02_normal","tabbar02_selected", "常用")
self.addChileViewControllers(UINavigationController(rootViewController: ThreeViewController()), "tabbar03_normal","tabbar03_selected", "发现")
self.addChileViewControllers(MainNavViewController(rootViewController: FourViewController()), "tabbar04_normal","tabbar04_selected", "我的")

}
func addChileViewControllers(_ childVC:UIViewController,_ imagename:String,_ selectImage:String,_ title:String) {
    self.addChildViewController(childVC)
    childVC.tabBarItem.image = UIImage.init(named: imagename)
    
    childVC.tabBarItem.selectedImage = UIImage.init(named: selectImage)?.withRenderingMode(.alwaysOriginal)
    UITabBarItem.appearance().setTitleTextAttributes([NSForegroundColorAttributeName:UIColor.black], for: .normal)
    UITabBarItem.appearance().setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.red], for: .selected)
    childVC.tabBarItem.title = title
}
override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}


/*
// MARK: - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    // Get the new view controller using segue.destinationViewController.
    // Pass the selected object to the new view controller.
}
*/

}

你可能感兴趣的:(7.4、精简分栏控制器)