一、加载storyboard进入初始化
func tabBarAddChildstoryBoradName(sbName: String, title: String, imageName: String, selectedImageName: String) {
//加载指定名称的sb文件
let sb = UIStoryboard(name: sbName, bundle: nil)
let vc = sb.instantiateInitialViewController()
//由storyboard进入
vc!.tabBarItem = UITabBarItem(title: title, image: UIImage(named: imageName), selectedImage: UIImage(named: selectedImageName))
vc!.view.backgroundColor = UIColor.whiteColor()
let nav = ZFBMainNavigationController(rootViewController: vc!)
vc!.navigationItem.title = title
addChildViewController(nav)
}
```
### 二、-加载类名进行初始化
func tabBarAddChildClassName(vcName: String, title: String, imageName: String, selectedImageName: String) {
//获取命名空间
let clsName = NSBundle.mainBundle().infoDictionary!["CFBundleExecutable"] as! String
//把字符串形式的类名称转换成类
let classType = NSClassFromString(clsName + "." + controllerName) as! UIViewController.Type
//通过class创建对象
let vc = classType.init()
//由viewcontroller直接添加
vc.tabBarItem = UITabBarItem(title: title, image: UIImage(named: imageName), selectedImage: UIImage(named: selectedImageName))
vc.view.backgroundColor = UIColor.whiteColor()
let nav = ZFBMainNavigationController(rootViewController: vc)
vc.navigationItem.title = title
addChildViewController(nav)
}
## //MARK: -加载swift文件进行初始化
func tabBarAddChildViewController(vc: UIViewController, title: String, imageName: String, selectedImageName: String){
//由viewcontroller直接添加
vc.tabBarItem = UITabBarItem(title: title, image: UIImage(named: imageName), selectedImage: UIImage(named: selectedImageName))
vc.view.backgroundColor = UIColor.whiteColor()
let nav = ZFBMainNavigationController(rootViewController: vc)
vc.navigationItem.title = title
addChildViewController(nav)
}