I Am developing a SwiftUI App for iOS that runs on iPhone and iPad. I am wondering if it is possible to show a tab bar on iPhone, but show a vertical side bar on iPad to make better use of the large screen. The tab bar and the side bar would have the same functionality, switching between tabs. It could look something like this Image I found on twitter except I don't need to have a macOs version of it. Could anyone help me out?
You need to add conditional check, somthing like folling:
struct TabSideBar: View {
#if os(iOS)
@Environment(\.horizontalSizeClass) private var horizontalSizeClass
#endif
@ViewBuilder var body: some View {
#if os(iOS)
if horizontalSizeClass == .compact {
TabBarContentView()
} else {
SideBarContentView()
}
#else //MacOSView
SideBarContentView()
#endif
}
}
Here is possible approach to have explicitly separated views for different devices
struct ContentView: View {
var body: some View {
if UIDevice.current.userInterfaceIdiom == .pad {
YourSidebarView()
} else {
YourTabView()
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With