Skip to content

Instantly share code, notes, and snippets.

@sturdysturge
Created January 24, 2021 17:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sturdysturge/e1cfce167ab3d9102f280608d5df6401 to your computer and use it in GitHub Desktop.
Save sturdysturge/e1cfce167ab3d9102f280608d5df6401 to your computer and use it in GitHub Desktop.
struct TopCornersMaskShape: Shape {
let radius: CGFloat
func path(in rect: CGRect) -> Path {
var path = Path()
let topLeftCorner = CGPoint(x: rect.minX + radius, y: rect.minY + radius)
let topRightCorner = CGPoint(x: rect.maxX - radius, y: rect.minY + radius)
let topLeftCornerStart = CGPoint(x: rect.minX, y: rect.minY + radius)
let topRightCornerStart = CGPoint(x: rect.maxX - radius, y: rect.minY)
let bottomRight = CGPoint(x: rect.maxX, y: rect.maxY)
let bottomLeft = CGPoint(x: rect.minX, y: rect.maxY)
path.move(to: topLeftCornerStart)
path.addRelativeArc(center: topLeftCorner, radius: radius, startAngle: .degrees(180), delta: .degrees(90))
path.addLine(to: topRightCornerStart)
path.addRelativeArc(center: topRightCorner, radius: radius, startAngle: .degrees(270), delta: .degrees(90))
path.addLine(to: bottomRight)
path.addLine(to: bottomLeft)
return path
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment