我想将Tabbar添加到我的应用程序中。即使我已经添加了代码,也不显示标签栏。如果无法从AppDelegate
添加UITableViewController
,该如何添加?我最好做什么?
class MainTableViewController: UITableViewController {
private func tabbar() {
let tabBarController = FluidTabBarController()
tabBarController.tabBar.tintColor = UIColor(red: 0.2431372549, green: 0.4235294118, blue: 1, alpha: 1)
let viewControllers = [
("News", #imageLiteral(resourceName: "output-onlinepngtools")),
].map(createSampleViewController)
tabBarController.setViewControllers(viewControllers, animated: true)
}
private func createSampleViewController(title: String, icon: UIImage) -> UIViewController {
let viewController = UIViewController()
viewController.view.backgroundColor = #colorLiteral(red: 0.9490196078, green: 0.9529411765, blue: 0.968627451, alpha: 1)
let item = FluidTabBarItem(title: title, image: icon, tag: 0)
item.imageColor = #colorLiteral(red: 0.7960784314, green: 0.8078431373, blue: 0.8588235294, alpha: 1)
viewController.tabBarItem = item
return viewController
}
override func viewDidLoad() {
super.viewDidLoad()
tabbar()
}
}
答案 0 :(得分:0)
我想这就是您要的,只是将ViewController嵌入到UITabBarController
如果要以编程方式执行此操作,则需要创建UITabBarController
并添加自定义视图控制器。在您的情况下,FirstViewController
将成为UITableViewController
class MyUITabBarController: UITabBarController {
override func viewDidLoad() {
super.viewDidLoad()
let firstViewController = FirstViewController()
firstViewController.tabBarItem = UITabBarItem(tabBarSystemItem: .search, tag: 0)
let secondViewController = SecondViewController()
secondViewController.tabBarItem = UITabBarItem(tabBarSystemItem: .more, tag: 1)
let tabBarList = [firstViewController, secondViewController]
viewControllers = tabBarList
}
}
然后在UITabBarController
中实例化您的didFinishLaunchingWithOptions
window?.rootViewController = MyUITabBarController()
window?.makeKeyAndVisible()
工作完成!