-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSwiftUI-RoundedCornersView.swift
More file actions
33 lines (29 loc) · 1.63 KB
/
SwiftUI-RoundedCornersView.swift
File metadata and controls
33 lines (29 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
struct RoundedCornersView: View {
var color: Color = .black
var topLeading: CGFloat = 0.0
var topTrailing: CGFloat = 0.0
var bottomLeading: CGFloat = 0.0
var bottomTrailing: CGFloat = 0.0
var body: some View {
GeometryReader { geometry in
Path { path in
let w = geometry.size.width
let h = geometry.size.height
let tr = min(min(self.topTrailing, h/2), w/2)
let tl = min(min(self.topLeading, h/2), w/2)
let bl = min(min(self.bottomLeading, h/2), w/2)
let br = min(min(self.bottomTrailing, h/2), w/2)
path.move(to: CGPoint(x: w / 2.0, y: 0))
path.addLine(to: CGPoint(x: w - tr, y: 0))
path.addArc(center: CGPoint(x: w - tr, y: tr), radius: tr, startAngle: Angle(degrees: -90), endAngle: Angle(degrees: 0), clockwise: false)
path.addLine(to: CGPoint(x: w, y: h - br))
path.addArc(center: CGPoint(x: w - br, y: h - br), radius: br, startAngle: Angle(degrees: 0), endAngle: Angle(degrees: 90), clockwise: false)
path.addLine(to: CGPoint(x: bl, y: h))
path.addArc(center: CGPoint(x: bl, y: h - bl), radius: bl, startAngle: Angle(degrees: 90), endAngle: Angle(degrees: 180), clockwise: false)
path.addLine(to: CGPoint(x: 0, y: tl))
path.addArc(center: CGPoint(x: tl, y: tl), radius: tl, startAngle: Angle(degrees: 180), endAngle: Angle(degrees: 270), clockwise: false)
}
.fill(self.color)
}
}
}