Anton Tropashko
Anton Tropashko

Reputation: 5806

How to show SwiftUI preview in landscape

.previewLayout(.fixed(width: 480, height: 320)) has no effect in Xcode 13.4 and Xcode 14 beta 3

The preview is shown in portrait vs expected landscape enter image description here

Upvotes: 3

Views: 500

Answers (1)

Steven-Carrot
Steven-Carrot

Reputation: 3051

To make it clear here, you did not actually set your preview in landscape mode. Two solutions for your problem:

  1. You actually requested the preview to be in a fixed size window, so to make this work, you need to choose Selectable in the canvas window to preview in a fixed sized window. I have drawn a red line around that part in the attached image. (code and image are below)

enter image description here

FContentView() //fixed size window
        .previewLayout(.fixed(width: 480, height: 320)) 
  1. If you want to actually preview in a landscape mode, use .previewInterfaceOrientation(.landscapeLeft) or right. You can choose either live / selectable. (code and image are below)

enter image description here

FContentView() //real landscape view
        .previewInterfaceOrientation(.landscapeLeft)

Upvotes: 1

Related Questions