Skip to content

Instantly share code, notes, and snippets.

@takoikatakotako
Created April 30, 2024 02:37
Show Gist options
  • Save takoikatakotako/0b4001f1c3fa1a88179b3f1020caaeca to your computer and use it in GitHub Desktop.
Save takoikatakotako/0b4001f1c3fa1a88179b3f1020caaeca to your computer and use it in GitHub Desktop.
SwiftUIでPreviewを横向きにする方法です。
import SwiftUI
struct ContentView: View {
@State var showingSnorlaxView = false
@State var showingSlowpokeView = false
var body: some View {
VStack {
Button(action: {
showingSnorlaxView = true
}) {
Text("Show Snorlax")
}
Button(action: {
showingSlowpokeView = true
}) {
Text("Show Slowpoke")
}
}
.sheet(isPresented: $showingSnorlaxView) {
SnorlaxView()
}
.sheet(isPresented: $showingSlowpokeView) {
SlowpokeView()
}
}
}
#Preview {
ContentView()
}
import SwiftUI
struct SlowpokeView: View {
var body: some View {
Image(.slowpoke)
.resizable()
.frame(width: 150, height: 150)
.scaledToFit()
}
}
import SwiftUI
struct SnorlaxView: View {
var body: some View {
Image(.snorlax)
.resizable()
.frame(width: 150, height: 150)
.scaledToFit()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment