一炭序、加載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創(chuàng)建對象
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)
}
最后編輯于 :
?著作權歸作者所有,轉載或內容合作請聯(lián)系作者