如何在 iOS swift 中根据设备大小添加更多标签栏项目?

How to add more tabbar items based on device size in iOS swift?

我正在尝试实现标签栏菜单。最初对于 iphone7 或 iphone 11 pro max,它应该显示 2 个菜单项。如果应用 运行 ipad 那么它应该在标签栏控制器中显示 4 个菜单项。

有可能实现吗?如果是的话,你能推荐给我样品吗..

例如 iphone7 或 iphone 11 pro max:

tabbar 项类似于 tab1 和 tab2

对于 ipad 个标签栏项目,例如 tab1、tab2、tab3 和 tab4。

非常感谢任何帮助...

iPhone、iPhone pro 或 iPad 最多 5 个。当您添加第六个时,您将获得第一个四个以及一个带有其他两个的“更多”选项卡。这不能使用标准 UITabBarController 进行更改。在点击更多选项卡时,您可以以网格方式显示多个选项卡。

搜索 github 或其他资源,例如 pods。

let firstVC = FirstViewController()
firstVC.tabBarItem = UITabBarItem(tabBarSystemItem: .one, tag: 0)

let secondVC = SecondViewController()

secondVC.tabBarItem = UITabBarItem(tabBarSystemItem: .two, tag: 1)

let thirdVC = ThirdViewController()
thirdVC.tabBarItem = UITabBarItem(tabBarSystemItem: .three, tag: 2)

let fourthVC = FourthViewController()
fourthVC.tabBarItem = UITabBarItem(tabBarSystemItem: .four, tag: 3)


if UIDevice.current.userInterfaceIdiom == .pad {
    let tabBarList = [firstVC, secondVC, thirdVC, fourthVC]
    viewControllers = tabBarList
} else {
    let tabBarList = [firstVC, secondVC]
    viewControllers = tabBarList
}

yourTabBarController.viewControllers = viewControllers