Created
June 20, 2020 08:18
-
-
Save gahntpo/b28daceffce7cdcfaf236c43a56c85bf to your computer and use it in GitHub Desktop.
GeometryReader in SwiftUI will give you the size at is available to layout the view
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
import SwiftUI | |
struct GeometryTestView: View { | |
var body: some View { | |
GeometryReader { geometry in | |
VStack { | |
Text("view width: \(geometry.size.width)") | |
Text("view height: \(geometry.size.height)") | |
HStack(spacing: 0) { | |
Rectangle() | |
.fill(Color.red) | |
.frame(width: geometry.size.width / 2) | |
Rectangle() | |
.fill(Color.green) | |
.frame(width: geometry.size.width / 2) | |
} | |
} | |
} | |
} | |
} | |
struct GeometryTestView_Previews: PreviewProvider { | |
static var previews: some View { | |
GeometryTestView() | |
.previewLayout(.fixed(width: 600, height: 300)) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment