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
|
var radius = 38.0
func path(in rect: CGRect) -> Path {
var path = Path()
let v = radius * 2
// 移动到0,0点
path.move(to: CGPoint(x: 0, y: 0))
// 画左上角90°圆弧
path.addArc(center: CGPoint(x: radius/2, y: radius/2), radius: radius/2, startAngle: Angle(degrees: 180), endAngle: Angle(degrees: 180+90), clockwise: false)
// 画中间水滴左边70°圆弧
path.addArc(center: CGPoint(x: ((rect.size.width / 2) - radius) - radius + v * 0.04 + radius/2, y: radius/2), radius: radius/2, startAngle: Angle(degrees: 270), endAngle: Angle(degrees: 270+70), clockwise: false)
// 画中间水滴圆弧
path.addArc(center: CGPoint(x: rect.size.width / 2, y: 0), radius: v/2, startAngle: Angle(degrees: 160), endAngle: Angle(degrees: 20), clockwise: true)
// 画中间水滴右边70°圆弧
path.addArc(center: CGPoint(x: (rect.size.width - ((rect.size.width / 2) - radius)) - v * 0.04 + radius/2, y: radius/2), radius: radius/2, startAngle: Angle(degrees: 200), endAngle: Angle(degrees: 200+70), clockwise: false)
// 画右上角90°圆弧
path.addArc(center: CGPoint(x: rect.size.width - radius/2, y: radius/2), radius: radius/2, startAngle: Angle(degrees: 270), endAngle: Angle(degrees: 270+90), clockwise: false)
// 画右边线
path.addLine(to: CGPoint(x: rect.size.width, y: rect.size.height))
// 画下边线
path.addLine(to: CGPoint(x: 0, y: rect.size.height))
// 自动闭合图形
return path
}
|