TEAM LICENSES: Save money and learn new skills through a Hacking with Swift+ team license >>

SOLVED: Any alternative to StackNavigationViewStyle()

Forums > SwiftUI

I was trying to make an app compatible on iPad however i do not want to use StackNavigationViewStyle() as below, as it breaks the way iPad users view content

struct ContentView: View {    
    var body: some View {
        NavigationView {
            Text("Hello world")

        }
        .navigationViewStyle(StackNavigationViewStyle())
    }
}

So i tried below code

struct ContentView: View {

    var body: some View {
        NavigationView {
                    Text("Hello world")
            if UIDevice.current.userInterfaceIdiom == .pad {
                            Text("Detail view content here")
                        }
            }
    }
}

this shows something like this in iPad

Burger menu at top and a detail screen on right

works well

but the problem is in iPhone when in landscape mode it shows with burger menu at top and blank screen

is there any way to correct this and show Hello world only in iPhone while showing a detail view in iPad on right

Thanks

2      

Hi! On iOS 16 there is NavigationSpitView available which works well for such purposes. Give it at try! There are many variants available...

struct ContentView: View {
    var body: some View {
        NavigationSplitView {
            Text("Hello, World!")
                .navigationTitle("SideBar")
        } detail: {
            Text("This is detail view!")
        }

    }
}

2      

Hacking with Swift is sponsored by Blaze.

SPONSORED Still waiting on your CI build? Speed it up ~3x with Blaze - change one line, pay less, keep your existing GitHub workflows. First 25 HWS readers to use code HACKING at checkout get 50% off the first year. Try it now for free!

Reserve your spot now

Sponsor Hacking with Swift and reach the world's largest Swift community!

Reply to this topic…

You need to create an account or log in to reply.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.