-->

Tabbar Item in Swift

2019-07-28 21:21发布

问题:

I have some issue in Tabbar controller. I put "FAQ" tab bar item in the bottom. When the app runs on the small screen devices, it automatically appears in More section.



The problem is that I put "Nav Bar" in FAQ view controller. For large screens (ipad), FAQ bar item shows in bottom. When Navbar item goes to More section, navbar is appear as two bar. One bar is that I make and another bar is default bar.
My current problem solving way is

 if (UIDevice.current.userInterfaceIdiom == UIUserInterfaceIdiom.pad)
    {   //ipad
       navBar.isHidden = false


    }
    else {
         navBar.isHidden = true

    }


I don't know that way is right or wrong.
Please help me how to remove Navbar when it appears in small screen. Now, I am using Swift 3 (Xcode 8).

English Language is not my native language. I'm sorry for my english grammar.

回答1:

For your use case, you can try this,

`if UIScreen.main.sizeType == .iPhone6Plus || UIScreen.main.sizeType == .iPhonePlus || UIScreen.main.sizeType == .iPhone6 || UIScreen.main.sizeType == .iPhoneX || UIScreen.main.sizeType == .iPhone5 {
     // for available iPhones
     navBar.isHidden = true
} else {
    // for iPad
    navBar.isHidden = false
}`

Basically, I am checking for all the available sizes of iPhones here and then doing what you want, accordingly. You can also manage your navigation bar in the viewDidAppear or viewDidLoad of the controller if you want. Do upvote the answer if this helps you. Feel free to comment for any other query or discussion. Happy Learning.