rotate swiftui preview

How do I rotate the SwiftUI Preview to show my view in landscape?

Post not yet marked as solved Up vote post of Ohmaar Down vote post of Ohmaar
6.3k views

Answers

I spoke to one of the engineers at WWDC about this. It is currently not possible. Your best bet is something like this:

#if DEBUG
struct ContentView_Previews : PreviewProvider {
    static var previews: some View {
        return ContentView().previewLayout(.fixed(width: 2688, height: 1242))
    }
}
#endif
Any updates on this? Would be nice to achieve this to test landscape iPad layout with the sidebar etc.
I am also bumping this issue up. It would be great to have some kind of orient control in SwitUI Preview
bump 🙃
Very Important feature for designing Pro apps. I hope apple can implement this soon. SwiftUI is amazing.

Also,

The correct screen resolution is:
Code Block swift
.previewLayout(.fixed(width: 2732, height: 2048))


As mentioned previously you can set a fixed height and width. However you should not put the pixel size in the fields, but the Point size. Without it you do not take the scale factor into account. for instance:

Code Block `
// iPhone X - Px res: 1125 x 2436 - Scale factor: 3.0
#if DEBUG
struct ContentView_Previews : PreviewProvider {
static var previews: some View {
return ContentView().previewLayout(.fixed(width: 2436 / 3.0, height: 1125 / 3.0))
}
}
#endif
`

After some tests, it looks like you have to use the UIKit Scale Factor and not the Native Scale factor for better preview rendering

Link to sizes and scale factor