先添加一個控制器spa
private func addChildViewController(vc:UIViewController,title:String, imageName:String ) {3d
let vc = HomeTableViewController()orm
vc.title = titleit
vc.tabBarItem.image = UIImage(named: imageName)io
let nav = UINavigationController(rootViewController: vc)sed
addChildViewController(nav)file
}im
而後在一個控制器中先添加四個按鈕margin
private func addChildViewControllers() {top
tabBar.tintColor = UIColor.orangeColor()
addChildViewController(HomeTableViewController(), title: "首頁", imageName: "tabbar_home")
addChildViewController(MessageTableViewController(), title: "消息", imageName: "tabbar_message_center")
addChildViewController (UIViewController())
addChildViewController(DiscoverTableViewController(), title: "發現", imageName: "tabbar_discover")
addChildViewController(ProfileTableViewController(), title: "我", imageName: "tabbar_profile")
}
最後在四個按鈕中間再添加一個按鈕
private func addComposedButton(){
tabBar.addSubview(composedButton)
let count = childViewControllers.count
let w = tabBar.bounds.width / CGFloat(count)
composedButton.frame = CGRectInset(tabBar.bounds, 2 * w, 0)
}