Swift

Swift TabBarController 实现

2020-06-15  本文已影响0人  江河_ios

方法实现

    override func viewDidLoad() {
    super.viewDidLoad()

    let onevc = SwiftOneViewController()
    let twovc = SwiftTwoViewController()
    let thirdVC = SwiftThirdViewController()

    self.addAnyViewControllerMessage(image: UIImage.init(named: "ic_launcher")!, selectoriImage: UIImage.init(named: "ic_launcher")!, title: "one", showvc: onevc)
    self.addAnyViewControllerMessage(image: UIImage.init(named: "ic_launcher")!, selectoriImage: UIImage.init(named: "ic_launcher")!, title: "two", showvc: twovc)
    self.addAnyViewControllerMessage(image: UIImage.init(named: "ic_launcher")!, selectoriImage: UIImage.init(named: "ic_launcher")!, title: "two", showvc: thirdVC)
}
//方法
func addAnyViewControllerMessage(image: UIImage, selectoriImage: UIImage, title:String, showvc: UIViewController)  {
  
    showvc.tabBarItem.title = title
    showvc.tabBarItem.selectedImage=selectoriImage
    showvc.tabBarItem.image=image
    tabBar.tintColor=UIColor.red
    let nav = UINavigationController.init(rootViewController: showvc)
    self.addChild(nav)

}
上一篇 下一篇

猜你喜欢

热点阅读