使用
创建子控制器继承自UITabBarController,在viewDidLoad阶段,把各个分页上的控制器给创建好,用UITabBarController的方法addChildControoler相关的方法就可以完成子控制器的添加。
be like:
private func creatChildController(vc:UIViewController,title:String,image:String,selected:String?){
vc.title = title
setTabbarImage(vc: vc, image: image, selected: selected)
let navVc = MainNaviController.init(rootViewController: vc)
addChild(navVc)
}
private func initChildrenController(){
let home = HomeController()
creatChildController(vc: home, title: "首页", image: "rectangle.tophalf.inset.filled", selected: "rectangle.bottomhalf.inset.filled")
let interset = InterestController()
creatChildController(vc: interset, title: "书影音", image: "heart.rectangle", selected: "heart.rectangle.fill")
let group = GroupController()
creatChildController(vc: group, title: "小组", image: "flag.filled.and.flag.crossed", selected: "flag.and.flag.filled.crossed")
let market = MarketController()
creatChildController(vc: market, title: "市集", image: "giftcard", selected: "giftcard.fill")
let profile = ProfileController()
creatChildController(vc: profile, title: "我", image: "shareplay", selected: nil)
}