Last active
June 23, 2021 13:12
-
-
Save tsif/00905439048e01b67625778fb0abd144 to your computer and use it in GitHub Desktop.
SwiftUI preview landscape view modifier
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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