Skip to content

Instantly share code, notes, and snippets.

@tsif
Last active June 23, 2021 13:12
Show Gist options
  • Save tsif/00905439048e01b67625778fb0abd144 to your computer and use it in GitHub Desktop.
Save tsif/00905439048e01b67625778fb0abd144 to your computer and use it in GitHub Desktop.
SwiftUI preview landscape view modifier
struct LandscapeModifier: ViewModifier {
func body(content: Content) -> some View {
content
.previewLayout(.fixed(width: 812, height: 375))
.environment(\.horizontalSizeClass, .compact)
.environment(\.verticalSizeClass, .compact)
}
}
extension View {
func landscape() -> some View {
self.modifier(LandscapeModifier())
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
.landscape()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment