steveluoxin
steveluoxin

Reputation: 436

SwiftUI TabView got wrong width in NavigationSplitView's side bar view when running on iPad simulator

I've been learning SwiftUI for a while, and it's really great. I run into a layout problem when I tried to add a TabView in sidebar view of NavigationSplitView. It's running as expected on iPhone simulator and Mac, but the width of TabView is wrong when running on iPad. It's wider than the sidebar that containing it.

Am I doing something wrong? Please help. Thanks.

struct TestView: View {
    var body: some View {
        NavigationSplitView {
            TabView {
                Text("This is sidebar 1")
                    .tabItem {
                        VStack {
                            Image(systemName: "gear")
                            Text("Sidebar 1")
                        }
                    }
                    .tag(0)
                Text("This is sidebar 2")
                    .tabItem {
                        VStack {
                            Image(systemName: "gear")
                            Text("Sidebar 2")
                        }
                    }
                    .tag(1)
            }
        } detail: {
            Text("This is detail")
        }
    }
}

enter image description here


Used a custom view with same result.

enter image description here

Upvotes: 0

Views: 200

Answers (0)

Related Questions