Swift创建UITabBarController
1、创建window
// 1.创建window
window = UIWindow(frame: UIScreen.mainScreen().bounds)
window?.backgroundColor = UIColor.whiteColor()
window?.rootViewController = MainViewController()//继承与UITabBarController控制器
// 2.显示window
window?.makeKeyAndVisible()
2、在MainViewController中
//函数重写添加标题以及图标
func addChildViewController(childController: UIViewController,title:String,imageName:String) {
childController.title = title;
childController.tabBarItem.image = UIImage(named: imageName)
childController.tabBarItem.selectedImage = UIImage(named: imageName + "_highlighted")
tabBar.tintColor = UIColor.orangeColor()
let nav = UINavigationController()
nav.addChildViewController(childController)
addChildViewController(nav)
}
3、viewdidload中调用并添加标题以及图片
addChildViewController(HomeViewController(),title:"首页",imageName:"tabbar_home")
addChildViewController(OrderViewController(),title:"订单",imageName: "tabbar_message_center")
addChildViewController(FreeViewController(),title: "费用",imageName: "tabbar_discover")
addChildViewController(MyViewController(), title: "我的", imageName: "tabbar_profile")