Last active
October 17, 2023 17:00
-
-
Save devs-rootstrap/acded95605fa74f62a45012a15e8f81c to your computer and use it in GitHub Desktop.
SwiftUI: GeometryReader examples
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 ContentView: View { | |
var body: some View { | |
GeometryReader { geometry in | |
VStack { | |
Spacer() | |
ZStack { | |
Rectangle() | |
.foregroundColor(.blue) | |
Circle() | |
.foregroundColor(.white) | |
.frame( | |
width: geometry.size.width * 0.5, | |
height: geometry.size.width * 0.5 | |
) | |
} | |
Spacer() | |
} | |
} | |
} | |
} |
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 ContentView: View { | |
var body: some View { | |
GeometryReader { geometry in | |
HStack(alignment: .center) { | |
Rectangle() | |
.frame(width: geometry.size.width / 2, height: geometry.size.height / 2) | |
.foregroundColor(.red) | |
.alignmentGuide(.leading) { d in d[HorizontalAlignment.center] } | |
Rectangle() | |
.frame(width: geometry.size.width / 2, height: geometry.size.height / 2) | |
.foregroundColor(.blue) | |
.alignmentGuide(.trailing) { d in d[HorizontalAlignment.center] } | |
} | |
} | |
.padding(10) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment