DFWatchCloseCircle.swift
2.69 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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
//
// DFWatchCloseCircle.swift
// iwatch
//
// Created by 权海 on 2026/6/12.
//
import SwiftUI
struct DFWatchCloseCircle: View {
var outerProgress: CGFloat
var middleProgress: CGFloat
var innerProgress: CGFloat
var outerColor: Color = Color(hex: "#FF5279")
var middleColor: Color = Color(hex: "#3BD49D")
var innerColor: Color = Color(hex: "#7B9BFB")
var backgroundColor: Color = .black
var body: some View {
GeometryReader { geometry in
let size = min(geometry.size.width, geometry.size.height)
let lineWidth: CGFloat = size * 0.13
ZStack {
backgroundColor
RingView(
progress: outerProgress,
color: outerColor,
lineWidth: lineWidth
)
.frame(
width: size * 0.87,
height: size * 0.87
)
RingView(
progress: middleProgress,
color: middleColor,
lineWidth: lineWidth
)
.frame(
width: size * 0.55,
height: size * 0.55
)
RingView(
progress: innerProgress,
color: innerColor,
lineWidth: lineWidth
)
.frame(
width: size * 0.24,
height: size * 0.24
)
Circle()
.fill(backgroundColor)
.frame(
width: size * 0.15,
height: size * 0.15
)
}
.frame(width: size, height: size)
.clipShape(Circle())
}
.aspectRatio(1, contentMode: .fit)
}
}
struct RingView: View {
var progress: CGFloat
var color: Color
var lineWidth: CGFloat
var body: some View {
ZStack{
Circle()
.stroke(
color,
style: StrokeStyle(
lineWidth: lineWidth,
lineCap: .round,
lineJoin: .round
)
)
.opacity(0.3)
Circle()
.trim(from: 0, to: max(0, min(progress, 1)))
.stroke(
color,
style: StrokeStyle(
lineWidth: lineWidth,
lineCap: .round,
lineJoin: .round
)
)
.rotationEffect(.degrees(-90))
}
}
}