import UIKit
class MainViewController: UITabBarController {
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = UIColor.brown
// 设置当前控制器对应的tabbar对应的颜色
// 注意:在ios7以前如果设置了tintColor只会改变字的颜色,图片的颜色不会改变
tabBar.tintColor = UIColor.orange
addChildViewController(childController: HomeViewController(), tittle: "首页", imageName: "tabbar_home")
addChildViewController(childController: MessageViewController(), tittle: "消息", imageName: "tabbar_message_center")
addChildViewController(childController: DiscoverViewController(), tittle: "广场", imageName: "tabbar_discover")
addChildViewController(childController: ProfileViewController(), tittle: "我", imageName: "tabbar_profile")
}
private func addChildViewController(childController: UIViewController,tittle:String ,imageName:String) {
// 1.设置首页对应的数据
childController.tabBarItem.image = UIImage(named: imageName)
childController.tabBarItem.selectedImage = UIImage(named: imageName + "_highlighted")
childController.title = tittle
// 2.给子控制器包装一个导航控制器
let nav = UINavigationController()
nav.addChildViewController(childController)
// 3.将导航控制器添加到当前控制器上
addChildViewController(nav)
}
}