Created
January 18, 2023 21:19
-
-
Save michaelevensen/63fdc0750485d8f10eb3a7523931b88b to your computer and use it in GitHub Desktop.
This file contains hidden or 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 GridView: View { | |
var lineWidth: CGFloat = 1.5 | |
var color = Color( | |
.displayP3, | |
red: 225/255, | |
green: 225/255, | |
blue: 225/255, | |
opacity: 1.0 | |
) | |
var spacing: CGSize = CGSize( | |
width: 48, | |
height: 48 | |
) | |
var body: some View { | |
GeometryReader { geometry in | |
Path { path in | |
// Draw vertical grid lines | |
for offsetX in stride(from: -lineWidth, to: geometry.size.width, by: self.spacing.width + lineWidth) { | |
path.move(to: CGPoint(x: offsetX, y: 0)) | |
path.addLine(to: CGPoint(x: offsetX, y: geometry.size.height)) | |
} | |
// Draw horizontal grid lines | |
for offsetY in stride(from: 0, to: geometry.size.height, by: self.spacing.height) { | |
path.move(to: CGPoint(x: 0, y: offsetY)) | |
path.addLine(to: CGPoint(x: geometry.size.height, y: offsetY)) | |
} | |
} | |
.stroke(color, lineWidth: lineWidth) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment