[英]How to add more tabbar items based on device size in iOS swift?
我正在嘗試實現標簽欄菜單。 最初對於 iphone7 或 iphone 11 pro max,它應該顯示 2 個菜單項。 如果應用程序運行 ipad 那么它應該在標簽欄 controller 中顯示 4 個菜單項。
有可能實現這一目標嗎? 如果是的話,你能推薦我的樣品嗎..
例如 iphone7 或 iphone 11 pro max:
標簽欄項目類似於 tab1 和 tab2
對於 ipad 標簽欄項目,如 tab1、tab2、tab3 和 tab4。
任何幫助非常感謝請...
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
在 iPhone、iPhone pro 或 iPad 上最多是 5 個。 當您添加第六個時,您將獲得第一個四個加上其他兩個選項卡的更多選項卡。 這不能使用標准的 UITabBarController 進行更改。 在點擊更多選項卡時,您可以以網格方式顯示多個選項卡。
搜索 github 或 pod 等其他資源。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.